Initial bringup of new set of ported GC tests.
authorSean Gillespie <segilles@microsoft.com>
Fri, 26 Feb 2016 22:56:07 +0000 (14:56 -0800)
committerSean Gillespie <sean.william.g@gmail.com>
Thu, 10 Mar 2016 01:31:37 +0000 (17:31 -0800)
Commit migrated from https://github.com/dotnet/coreclr/commit/f7c51223d7b3a0153b002b30f619a7f02ff4fc99

472 files changed:
src/coreclr/tests/issues.targets
src/coreclr/tests/src/GC/API/GC/AddMemoryPressureTest.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/AddMemoryPressureTest.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/AddThresholdTest.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/AddThresholdTest.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/AddUsageTest.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/AddUsageTest.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect0.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect0.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect1.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect1.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_Default.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_Default_1.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_Default_2.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_Default_3.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_Forced.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_Forced_1.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_Forced_2.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_Forced_3.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_Optimized.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_Optimized_1.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_Optimized_2.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_Optimized_3.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_fail.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_fail.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_neg.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Collect_neg.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/CollectionCountTest.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/CollectionCountTest.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Finalize.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/Finalize.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/GetGeneration.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/GetGeneration.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/GetGenerationWR.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/GetGenerationWR.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/GetGenerationWR2.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/GetGenerationWR2.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/GetGeneration_box.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/GetGeneration_box.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/GetGeneration_fail.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/GetGeneration_fail.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/GetTotalMemory.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/GetTotalMemory.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/KeepAlive.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/KeepAlive.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/KeepAliveNull.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/KeepAliveNull.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/KeepAliveRecur.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/KeepAliveRecur.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/MaxGeneration.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/MaxGeneration.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/ReRegisterForFinalize.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/ReRegisterForFinalize.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/ReRegisterForFinalize_null.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/ReRegisterForFinalize_null.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/RemoveMemoryPressureTest.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/RemoveMemoryPressureTest.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/RemoveUsageTest.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/RemoveUsageTest.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/SuppressFinalize.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/SuppressFinalize.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/SuppressFinalize_Null.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/SuppressFinalize_Null.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/TotalMemory.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/TotalMemory.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/TotalMemory2.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/TotalMemory2.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GC/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/AddrOfPinnedObject.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/AddrOfPinnedObject.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/AddrOfPinnedObject_neg.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/AddrOfPinnedObject_neg.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Alloc.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Alloc.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Alloc_neg.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Alloc_neg.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Alloc_neg2.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Alloc_neg2.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Casting.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Casting.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Equality.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Equality.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Free.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Free.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Free_neg.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Free_neg.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/HandleCopy.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/HandleCopy.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/IsAllocated.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/IsAllocated.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Normal.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Normal.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/PinObj_neg.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/PinObj_neg.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Pinned.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Pinned.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Target.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Target.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Target_neg.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Target_neg.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/ToFromIntPtr.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/ToFromIntPtr.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Weak.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/Weak.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandle/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandleCollector/Count.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandleCollector/Count.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandleCollector/CtorsAndProperties.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandleCollector/CtorsAndProperties.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandleCollector/NegTests.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandleCollector/NegTests.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandleCollector/Usage.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandleCollector/Usage.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCHandleCollector/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCSettings/ILatencyTest.csproj
src/coreclr/tests/src/GC/API/GCSettings/InducedGen0GC.csproj
src/coreclr/tests/src/GC/API/GCSettings/InducedGen1GC.csproj
src/coreclr/tests/src/GC/API/GCSettings/InducedGen2GC.csproj
src/coreclr/tests/src/GC/API/GCSettings/InputValidation.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCSettings/InputValidation.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/GCSettings/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/Finalize.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/Finalize.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/Finalize2.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/Finalize2.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/IsAlive.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/IsAlive.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/IsAlive_neg.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/IsAlive_neg.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/NullHandle.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/NullHandle.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/Target.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/Target.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/TrackResurrection.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/TrackResurrection.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/multipleWRs.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/multipleWRs.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/API/WeakReference/multipleWRs_1.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Coverage/271010.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Coverage/271010.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Coverage/LargeObjectAlloc.csproj
src/coreclr/tests/src/GC/Coverage/LargeObjectAlloc2.csproj
src/coreclr/tests/src/GC/Coverage/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Coverage/concurrentspin2.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Coverage/concurrentspin2.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Coverage/delete_next_card_table.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Coverage/delete_next_card_table.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Coverage/smalloom.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Coverage/smalloom.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/BackgroundGC/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/BackgroundGC/concurrentspin2.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/BackgroundGC/concurrentspin2.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/BackgroundGC/foregroundgc.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/BackgroundGC/foregroundgc.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeio/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeio/finalizeio.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeio/finalizeio.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizearray.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizearray.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizearraysleep.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizearraysleep.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizedest.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizedest.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizedirectedgraph.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizedirectedgraph.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizeexcep.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizeexcep.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizeinherit.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizeinherit.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizenested.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizenested.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/HeapExpansion/Finalizer.csproj
src/coreclr/tests/src/GC/Features/HeapExpansion/GCUtil_HeapExpansion.csproj
src/coreclr/tests/src/GC/Features/HeapExpansion/Handles.csproj
src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit-finalize.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit-finalize.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit-threaded.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit-threaded.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit_1.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/HeapExpansion/expandheap.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/HeapExpansion/expandheap.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/HeapExpansion/plug.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/HeapExpansion/plug.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/HeapExpansion/pluggaps.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/HeapExpansion/pluggaps.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/HeapExpansion/project.json [deleted file]
src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivearray.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivearray.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivedirectedgraph.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivedirectedgraph.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivefinalize.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivefinalize.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivehandle.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivehandle.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivescope.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivescope.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivetry.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivetry.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivetypes.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivetypes.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHCompaction/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompact_stress.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompact_stress.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi2.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi2.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi_exceptions.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi_exceptions.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactscenariorepro.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactscenariorepro.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHCompaction/lohpin.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHCompaction/lohpin.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHFragmentation/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHFragmentation/lohfragmentation.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/LOHFragmentation/lohfragmentation.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/PartialCompaction/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/PartialCompaction/eco1.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/PartialCompaction/eco1.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/PartialCompaction/partialcompactiontest.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/PartialCompaction/partialcompactiontest.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/PartialCompaction/partialcompactionwloh.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/PartialCompaction/partialcompactionwloh.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/Pinning/PinningOther/GCUtil_Pinning.csproj
src/coreclr/tests/src/GC/Features/Pinning/PinningOther/PinnedCollect.csproj
src/coreclr/tests/src/GC/Features/Pinning/PinningOther/PinnedHandle.csproj
src/coreclr/tests/src/GC/Features/Pinning/PinningOther/PinnedInt.csproj
src/coreclr/tests/src/GC/Features/Pinning/PinningOther/PinnedMany.csproj
src/coreclr/tests/src/GC/Features/Pinning/PinningOther/PinnedMultiple.csproj
src/coreclr/tests/src/GC/Features/Pinning/PinningOther/PinnedObject.csproj
src/coreclr/tests/src/GC/Features/Pinning/PinningOther/project.json [deleted file]
src/coreclr/tests/src/GC/Features/SustainedLowLatency/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/SustainedLowLatency/scenario.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/SustainedLowLatency/scenario.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/SustainedLowLatency/sustainedlowlatency_race.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/SustainedLowLatency/sustainedlowlatency_race.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/SustainedLowLatency/sustainedlowlatency_race_reverse.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Features/SustainedLowLatency/sustainedlowlatency_race_reverse.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/API/gc/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/API/gc/collect.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/API/gc/collect.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/API/gc/getgeneration.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/API/gc/getgeneration.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/API/gc/gettotalmemory.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/API/gc/gettotalmemory.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/API/gc/keepalive.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/API/gc/keepalive.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/API/gc/largeobject.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/API/gc/largeobject.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/API/gc/reregisterforfinalize.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/API/gc/reregisterforfinalize.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/API/gc/suppressfinalize.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/API/gc/suppressfinalize.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/Allocation/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/Allocation/finalizertest.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/Allocation/finalizertest.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/Allocation/largeexceptiontest.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/Allocation/largeexceptiontest.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/Allocation/largeobject.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/Allocation/largeobject.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/Regressions/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/Regressions/largearraytest.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/Regressions/largearraytest.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/Regressions/pressureoverflow.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/LargeMemory/Regressions/pressureoverflow.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/M10/RefCrossTHDs/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/M10/RefCrossTHDs/refcrossthds.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/M10/RefCrossTHDs/refcrossthds.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/dev10bugs/536168/536168.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/dev10bugs/536168/536168.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/dev10bugs/536168/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta1/149926/149926.cs
src/coreclr/tests/src/GC/Regressions/v2.0-beta1/149926/149926.csproj
src/coreclr/tests/src/GC/Regressions/v2.0-beta1/149926/project.json [deleted file]
src/coreclr/tests/src/GC/Regressions/v2.0-beta1/289745/289745.cs
src/coreclr/tests/src/GC/Regressions/v2.0-beta1/289745/289745.csproj
src/coreclr/tests/src/GC/Regressions/v2.0-beta1/289745/302560.csproj
src/coreclr/tests/src/GC/Regressions/v2.0-beta1/289745/project.json [deleted file]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/426480/426480.csproj
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/426480/project.json [deleted file]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/437657/437657.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/437657/437657.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/437657/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/445488/445488.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/445488/445488.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/445488/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/452950/452950.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/452950/452950.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/452950/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/460373/460373.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/460373/460373.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/460373/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/462651/462651.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/462651/462651.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/462651/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/471729/471729.csproj
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/471729/project.json [deleted file]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/476725/ManagedTest.csproj
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/476725/project.json [deleted file]
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/485617/Managed.csproj
src/coreclr/tests/src/GC/Regressions/v2.0-beta2/485617/project.json [deleted file]
src/coreclr/tests/src/GC/Regressions/v2.0-rtm/494226/494226.csproj
src/coreclr/tests/src/GC/Regressions/v2.0-rtm/494226/project.json [deleted file]
src/coreclr/tests/src/GC/Regressions/v2.0-rtm/544701/544701.cs
src/coreclr/tests/src/GC/Regressions/v2.0-rtm/544701/544701.csproj
src/coreclr/tests/src/GC/Regressions/v2.0-rtm/544701/project.json [deleted file]
src/coreclr/tests/src/GC/Scenarios/Affinity/affinitizer.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Affinity/affinitizer.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Affinity/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/BaseFinal/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/BaseFinal/basefinal.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/BaseFinal/basefinal.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/BinTree/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/BinTree/bintree.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/BinTree/bintree.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/BinTree/thdtree.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/BinTree/thdtree.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/BinTree/thdtreegrowingobj.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/BinTree/thdtreegrowingobj.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/BinTree/thdtreelivingobj.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/BinTree/thdtreelivingobj.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/BinTree/treethread.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/arrcpy.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/arrcpy.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/doubLink.csproj
src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant2.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant2.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant3.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant3.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant4.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant4.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/project.json [deleted file]
src/coreclr/tests/src/GC/Scenarios/Boxing/simpvariant.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/simpvariant.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/vararystress.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/vararystress.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/variantint.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/variantint.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/variantlinklist.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Boxing/variantlinklist.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/DoubLink.csproj
src/coreclr/tests/src/GC/Scenarios/DoublinkList/DoubLink_V2.csproj
src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlbigleak.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlbigleak.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlbigleakthd.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlbigleakthd.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlbigleakthd_v2.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlcollect.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlcollect.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlstack.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlstack.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinkgen.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinkgen.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinknoleak.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinknoleak.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinknoleak2.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinknoleak2.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinkstay.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinkstay.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/DoublinkList/project.json [deleted file]
src/coreclr/tests/src/GC/Scenarios/Dynamo/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Dynamo/basenode.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Dynamo/dynamo.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Dynamo/dynamo.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Dynamo/dynamonode.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Dynamo/randomnode.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Dynamo/staticnode.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/FinalNStruct/finalnstruct.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/FinalNStruct/finalnstruct.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/FinalNStruct/nstructresur.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/FinalNStruct/nstructresur.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/FinalNStruct/nstructtun.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/FinalNStruct/nstructtun.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/FinalNStruct/project.json [deleted file]
src/coreclr/tests/src/GC/Scenarios/FinalNStruct/strmap.csproj
src/coreclr/tests/src/GC/Scenarios/FinalizeTimeout/FinalizeTimeout.csproj
src/coreclr/tests/src/GC/Scenarios/FinalizeTimeout/project.json [deleted file]
src/coreclr/tests/src/GC/Scenarios/FragMan/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/FragMan/fragman.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/FragMan/fragman.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/GCBase1/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/GCBase1/gc_base1.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/GCBase1/gc_base1.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/GCBase1/gc_base1_1.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/GCBench/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/GCBench/gcbench.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/GCBench/gcbench.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/GCStress/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/GCStress/gcstress.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/GCStress/gcstress.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/LeakGen/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/LeakGen/leakgen.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/LeakGen/leakgen.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/LeakGen/leakgenthrd.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/LeakGen/leakgenthrd.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/LeakWheel/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/LeakWheel/leakwheel.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/LeakWheel/leakwheel.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/MinLeakGen/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/MinLeakGen/minleakgen.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/MinLeakGen/minleakgen.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/NDPin/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/NDPin/ndpin.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/NDPin/ndpin.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/NDPin/ndpinfinal.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/NDPin/ndpinfinal.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/RanCollect/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/RanCollect/rancollect.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/RanCollect/rancollect.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/ReflectObj/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/ReflectObj/reflectobj.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/ReflectObj/reflectobj.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Resurrection/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Resurrection/continue.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Resurrection/continue.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Rootmem/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Rootmem/rootmem.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Rootmem/rootmem.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Samples/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Samples/gc.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/Samples/gc.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/ServerModel/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/ServerModel/cache.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/ServerModel/parameters.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/ServerModel/request.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/ServerModel/server.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/ServerModel/servermodel.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/ServerModel/servermodel.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/ServerModel/settings.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/SingLinkList/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/SingLinkList/singlinkgen.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/SingLinkList/singlinkgen.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/SingLinkList/singlinkstay.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/SingLinkList/singlinkstay.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/StringCreator/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/StringCreator/stringcreator.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/StringCreator/stringcreator.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/THDChaos/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/THDChaos/livingobject.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/THDChaos/masterthread.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/THDChaos/thdchaos.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/THDChaos/thdchaos.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/THDList/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/THDList/linkedlist.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/THDList/llthread.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/THDList/thdlist.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/THDList/thdlist.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/WeakReference/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/WeakReference/getgencollect.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/WeakReference/getgencollect.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/WeakReference/weakref.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/WeakReference/weakref.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/WeakReference/weakreffinal.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/WeakReference/weakreffinal.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/muldimjagary/app.config [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/muldimjagary/muldimjagary.cs [new file with mode: 0644]
src/coreclr/tests/src/GC/Scenarios/muldimjagary/muldimjagary.csproj [new file with mode: 0644]
src/coreclr/tests/src/GC/config/extra/project.json [moved from src/coreclr/tests/src/GC/Coverage/project.json with 92% similarity]
src/coreclr/tests/src/GC/config/minimal/project.json [moved from src/coreclr/tests/src/GC/API/GCSettings/project.json with 95% similarity]
src/coreclr/tests/src/GC/dir.props [new file with mode: 0644]
src/coreclr/tests/testsFailingOutsideWindows.txt
src/coreclr/tests/testsUnsupportedOutsideWindows.txt
src/coreclr/tests/x86_legacy_backend_issues.targets

index c0d217b..308c93b 100644 (file)
         </ExcludeList>
         <ExcludeList Include="$(XunitTestBinBase)\Interop\BestFitMapping\BestFitMapping\BestFitMapping.cmd" >
              <Issue>3571</Issue>
+       </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\API\WeakReference\Finalize2\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\API\WeakReference\NullHandle\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\API\WeakReference\Target\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\API\WeakReference\IsAlive\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\API\WeakReference\IsAlive_neg\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Features\Finalizer\finalizeother\finalizedirectedgraph\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\LargeMemory\Allocation\finalizertest\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\LargeMemory\Allocation\finalizertest\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\LargeMemory\API\gc\reregisterforfinalize\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\LargeMemory\API\gc\collect\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\DoublinkList\doublinknoleak2\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\DoublinkList\doublinknoleak\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\LeakWheel\leakwheel\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\SingLinkList\singlinkgen\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\WeakReference\getgencollect\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\WeakReference\weakref\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\LargeMemory\API\gc\getgeneration\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\BaseFinal\basefinal\*">
+             <Issue>3391</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Coverage\concurrentspin2\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Coverage\smalloom\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Coverage\271010\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Features\BackgroundGC\concurrentspin2\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Features\BackgroundGC\foregroundgc\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Features\LOHCompaction\lohcompact_stress\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Features\LOHCompaction\lohcompactscenariorepro\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Features\LOHCompaction\lohcompactapi2\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Features\LOHFragmentation\lohfragmentation\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Features\PartialCompaction\partialcompactiontest\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Features\PartialCompaction\partialcompactionwloh\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Features\PartialCompaction\eco1\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Features\SustainedLowLatency\sustainedlowlatency_race_reverse\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Features\SustainedLowLatency\scenario\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Features\SustainedLowLatency\sustainedlowlatency_race\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Regressions\dev10bugs\536168\536168\*">
+             <Issue>3392</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\muldimjagary\muldimjagary\*">
+             <Issue>3392</Issue>
         </ExcludeList>
     </ItemGroup>
 </Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/AddMemoryPressureTest.cs b/src/coreclr/tests/src/GC/API/GC/AddMemoryPressureTest.cs
new file mode 100644 (file)
index 0000000..52b98eb
--- /dev/null
@@ -0,0 +1,210 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/* AddMemoryPressureTest
+ *
+ * Tests GC.AddMemoryPressure by passing it values that are too small (<=0) and
+ * values that are too large (>Int32.MaxValue on 32-bit).
+ * The stress test doubles the pressure (2xInt32.MaxValue), and verifies
+ * valid behaviour.
+ */
+
+
+
+
+using System;
+using System.Diagnostics;
+using System.Security;
+using System.Runtime.InteropServices;
+
+public class Dummy
+{
+    private long _pressure = 0;
+    private int _numTimes = 0;
+
+    public Dummy(bool heavy)
+    {
+        if (heavy)
+        {
+            _pressure = Int32.MaxValue;
+            _numTimes = 2;
+            for (int i = 0; i < _numTimes; i++)
+                GC.AddMemoryPressure(_pressure);
+        }
+    }
+
+    ~Dummy()
+    {
+        for (int i = 0; i < _numTimes; i++)
+            GC.RemoveMemoryPressure(_pressure);
+    }
+}
+
+public class AddMemoryPressureTest
+{
+    public int TestCount = 0;
+
+    private long[] _negValues = { 0, -1, Int32.MinValue - (long)1, Int64.MinValue / (long)2, Int64.MinValue };
+    private long[] _largeValues = { Int32.MaxValue + (long)1, Int64.MaxValue };
+
+
+    private AddMemoryPressureTest()
+    {
+    }
+
+
+    public bool TooSmallTest()
+    {
+        TestCount++;
+        bool retVal = true;
+
+        foreach (long i in _negValues)
+        {
+            try
+            {
+                GC.AddMemoryPressure(i);
+                Console.WriteLine("Failure at TooSmallTest: {0}", i);
+                retVal = false;
+                break;
+            }
+            catch (ArgumentOutOfRangeException)
+            {
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e.Message);
+                Console.WriteLine("Failure at TooSmallTest: {0}", i);
+                retVal = false;
+                break;
+            }
+        }
+
+        if (retVal)
+            Console.WriteLine("TooSmallTest Passed");
+        return retVal;
+    }
+
+
+    public bool TooLargeTest()
+    {
+        TestCount++;
+
+        bool retVal = true;
+
+        foreach (long i in _largeValues)
+        {
+            try
+            {
+                GC.AddMemoryPressure(i);
+                // this should not throw exception on 64-bit
+                if (IntPtr.Size == Marshal.SizeOf(new Int32()))
+                {
+                    Console.WriteLine("Failure at LargeValueTest: {0}", i);
+                    retVal = false;
+                    break;
+                }
+                else
+                {
+                    GC.RemoveMemoryPressure(i);
+                }
+            }
+            catch (ArgumentOutOfRangeException)
+            {
+                // this should not throw exception on 64-bit
+                if (IntPtr.Size == Marshal.SizeOf(new Int64()))
+                {
+                    Console.WriteLine("Failure at LargeValueTest: {0}", i);
+                    retVal = false;
+                    break;
+                }
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e.Message);
+                retVal = false;
+                break;
+            }
+        }
+
+        if (retVal)
+            Console.WriteLine("TooLargeTest Passed");
+        return retVal;
+    }
+
+
+    public bool StressTest()
+    {
+        TestCount++;
+
+        Console.WriteLine("StressTest Started...");
+
+        int gcCount1 = createDummies(true);
+
+
+        int gcCount2 = createDummies(false);
+
+        Console.WriteLine("{0} {1}", gcCount1, gcCount2);
+        if (gcCount1 > gcCount2)
+        {
+            Console.WriteLine("StressTest Passed");
+            Console.WriteLine();
+            return true;
+        }
+
+        Console.WriteLine("StressTest Failed");
+
+        Console.WriteLine();
+        return false;
+    }
+
+
+    private int createDummies(bool heavy)
+    {
+        int gcCount = GC.CollectionCount(0);
+
+        for (int i = 0; i < 100; i++)
+        {
+            Dummy dummy = new Dummy(heavy);
+            int gen = GC.GetGeneration(dummy);
+            if (gen != 0)
+            {
+                Console.WriteLine("Warning: newly-allocated dummy ended up in gen {0}", gen);
+            }
+        }
+
+        return GC.CollectionCount(0) - gcCount;
+    }
+
+
+    public bool RunTest()
+    {
+        int passCount = 0;
+
+        if (TooSmallTest())
+            passCount++;
+
+        if (TooLargeTest())
+            passCount++;
+
+        if (StressTest())
+            passCount++;
+
+        return (passCount == TestCount);
+    }
+
+
+    public static int Main()
+    {
+        AddMemoryPressureTest test = new AddMemoryPressureTest();
+
+        if (test.RunTest())
+        {
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test Failed");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/AddMemoryPressureTest.csproj b/src/coreclr/tests/src/GC/API/GC/AddMemoryPressureTest.csproj
new file mode 100644 (file)
index 0000000..75a51ec
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="AddMemoryPressureTest.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/AddThresholdTest.cs b/src/coreclr/tests/src/GC/API/GC/AddThresholdTest.cs
new file mode 100644 (file)
index 0000000..d495d6a
--- /dev/null
@@ -0,0 +1,110 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/* AddUsageTest
+ *
+ * Tests GC.AddMemoryPressure by passing a valid value (AddMemoryPressureTest.Pressure)
+ * and making sure the objects with added pressure get collected more times by
+ * the GC than those without pressure.
+ */
+
+
+using System;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+
+public class Dummy
+{
+    public Dummy(long pressure)
+    {
+        GC.AddMemoryPressure(pressure);
+    }
+
+    public Dummy()
+    {
+    }
+}
+
+
+
+public class AddUsageTest
+{
+    public static int Pressure = 100000; // test will fail with values less than this
+    private int _numTests = 0;
+
+
+    private AddUsageTest()
+    {
+    }
+
+
+    public bool ThresholdTest()
+    {
+        _numTests++;
+
+        int gcCount1 = GC.CollectionCount(0);
+        for (int i = 0; i < 100; i++)
+        {
+            Dummy heavy = new Dummy(AddUsageTest.Pressure);
+            int gen = GC.GetGeneration(heavy);
+            if (gen != 0)
+            {
+                Console.WriteLine("Warning: newly-allocated dummy ended up in gen {0}", gen);
+            }
+            //GC.WaitForPendingFinalizers();
+        }
+        gcCount1 = GC.CollectionCount(0) - gcCount1;
+
+
+        int gcCount2 = GC.CollectionCount(0);
+        for (int i = 0; i < 100; i++)
+        {
+            Dummy light = new Dummy(AddUsageTest.Pressure);
+            int gen = GC.GetGeneration(light);
+            if (gen != 0)
+            {
+                Console.WriteLine("Warning: newly-allocated dummy ended up in gen {0}", gen);
+            }
+            //GC.WaitForPendingFinalizers();
+        }
+        gcCount2 = GC.CollectionCount(0) - gcCount2;
+
+        Console.WriteLine("{0} {1}", gcCount1, gcCount2);
+        if (gcCount1 > gcCount2)
+        {
+            Console.WriteLine("ThresholdTest Passed");
+            Console.WriteLine();
+            return true;
+        }
+
+        Console.WriteLine("ThresholdTest Failed");
+        Console.WriteLine();
+        return false;
+    }
+
+
+    public bool RunTest()
+    {
+        int numPass = 0;
+
+        if (ThresholdTest())
+            numPass++;
+
+        return (numPass == _numTests);
+    }
+
+    public static int Main()
+    {
+        AddUsageTest test = new AddUsageTest();
+
+        if (test.RunTest())
+        {
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test Failed");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/AddThresholdTest.csproj b/src/coreclr/tests/src/GC/API/GC/AddThresholdTest.csproj
new file mode 100644 (file)
index 0000000..d98edd8
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="AddThresholdTest.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/AddUsageTest.cs b/src/coreclr/tests/src/GC/API/GC/AddUsageTest.cs
new file mode 100644 (file)
index 0000000..f3ac783
--- /dev/null
@@ -0,0 +1,112 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/* AddUsageTest
+ *
+ * Tests GC.AddMemoryPressure by passing a valid value (AddMemoryPressureTest.Pressure)
+ * and making sure the objects with added pressure get collected more times by
+ * the GC than those without pressure.
+ */
+
+
+using System;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+
+public class Dummy
+{
+    public Dummy(long pressure)
+    {
+        GC.AddMemoryPressure(pressure);
+    }
+
+    public Dummy()
+    {
+    }
+}
+
+
+
+public class AddUsageTest
+{
+    public static int Pressure = 100000; // test will fail with values less than this
+    private int _numTests = 0;
+
+
+    private AddUsageTest()
+    {
+    }
+
+
+
+
+    public bool AddTest()
+    {
+        _numTests++;
+
+        int gcCount1 = GC.CollectionCount(0);
+        for (int i = 0; i < 100; i++)
+        {
+            Dummy heavy = new Dummy(AddUsageTest.Pressure);
+            int gen = GC.GetGeneration(heavy);
+            if (gen != 0)
+            {
+                Console.WriteLine("Warning: newly-allocated dummy ended up in gen {0}", gen);
+            }
+            //GC.WaitForPendingFinalizers();
+        }
+        gcCount1 = GC.CollectionCount(0) - gcCount1;
+
+
+        int gcCount2 = GC.CollectionCount(0);
+        for (int i = 0; i < 100; i++)
+        {
+            Dummy light = new Dummy();
+            int gen = GC.GetGeneration(light);
+            if (gen != 0)
+            {
+                Console.WriteLine("Warning: newly-allocated dummy ended up in gen {0}", gen);
+            }
+            //GC.WaitForPendingFinalizers();
+        }
+        gcCount2 = GC.CollectionCount(0) - gcCount2;
+
+        Console.WriteLine("{0} {1}", gcCount1, gcCount2);
+        if (gcCount1 > gcCount2)
+        {
+            Console.WriteLine("AddTest Passed");
+            Console.WriteLine();
+            return true;
+        }
+
+        Console.WriteLine("AddTest Failed");
+        Console.WriteLine();
+        return false;
+    }
+
+    public bool RunTest()
+    {
+        int numPass = 0;
+
+
+        if (AddTest())
+            numPass++;
+
+        return (numPass == _numTests);
+    }
+
+    public static int Main()
+    {
+        AddUsageTest test = new AddUsageTest();
+
+        if (test.RunTest())
+        {
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test Failed");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/AddUsageTest.csproj b/src/coreclr/tests/src/GC/API/GC/AddUsageTest.csproj
new file mode 100644 (file)
index 0000000..ddf2da2
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="AddUsageTest.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect.cs b/src/coreclr/tests/src/GC/API/GC/Collect.cs
new file mode 100644 (file)
index 0000000..0c4931b
--- /dev/null
@@ -0,0 +1,32 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+// Tests GC.Collect()
+
+using System;
+
+public class Test {
+       public static int Main() {
+
+               Object obj1 = new Object();
+               int[] array = new int[25];
+               
+               int gen1 = GC.GetGeneration(array);
+
+               Console.WriteLine("Array is in generation: " + gen1);
+               GC.Collect();
+
+               int gen2 = GC.GetGeneration(array);
+               Console.WriteLine("Array is in generation: " + gen2);
+
+               if(((gen1==2) && (gen2==2)) || (gen2>gen1)) {    // was already in gen 2!
+                       Console.WriteLine("Test for GC.Collect() passed!");
+            return 100;
+               }
+
+               else {
+                       Console.WriteLine("Test for GC.Collect() failed!");
+            return 1;
+               }
+       }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect.csproj b/src/coreclr/tests/src/GC/API/GC/Collect.csproj
new file mode 100644 (file)
index 0000000..9b4da63
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Collect.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect0.cs b/src/coreclr/tests/src/GC/API/GC/Collect0.cs
new file mode 100644 (file)
index 0000000..5d5d54b
--- /dev/null
@@ -0,0 +1,52 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+// Tests GC.Collect(0)
+
+using System;
+
+public class Test {
+       public static int Main() {
+
+               int[] array = new int[25];
+               int agen1 = GC.GetGeneration(array);
+
+               Console.WriteLine("Array is in generation: " + agen1);
+               
+               if(agen1 != 0) {
+                       Console.WriteLine("Running under stress..");
+            return 100;
+               }
+               
+               //GC.Collect();
+
+               Object obj = new Object();
+               int ogen1 = GC.GetGeneration(obj);
+
+               Console.WriteLine("Object is in generation: " + ogen1);
+               Console.WriteLine("Collect(0)");
+               GC.Collect(0);
+               GC.Collect(0);
+
+               int agen2 = GC.GetGeneration(array);
+               int ogen2 = GC.GetGeneration(obj);
+                       
+               if(agen2 > 1) {
+                       Console.WriteLine("Running under stress..");
+            return 100;
+               }
+
+               Console.WriteLine("Array is in generation: {0}",agen2);
+               Console.WriteLine("Object is in generation: {0}",ogen2);
+               
+               if(agen2 == ogen2) {     // only gen 0 was collected
+                       Console.WriteLine("Test for GC.Collect(0) passed!");
+            return 100;
+               }
+
+               else {
+                       Console.WriteLine("Test for GC.Collect(0) failed!");
+            return 1;
+               }
+       }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect0.csproj b/src/coreclr/tests/src/GC/API/GC/Collect0.csproj
new file mode 100644 (file)
index 0000000..3b742e4
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Collect0.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect1.cs b/src/coreclr/tests/src/GC/API/GC/Collect1.cs
new file mode 100644 (file)
index 0000000..689f055
--- /dev/null
@@ -0,0 +1,49 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GC.Collect(1)
+
+using System;
+
+public class Test
+{
+    public static int Main()
+    {
+        int[] array = new int[25];
+        int agen1 = GC.GetGeneration(array);
+        Console.WriteLine("Array is in generation: " + agen1);
+
+        GC.Collect();
+
+        Object obj = new Object();
+        int ogen1 = GC.GetGeneration(obj);
+        Console.WriteLine("Object is in generation: " + ogen1);
+
+        Console.WriteLine("Collect(1)");
+        GC.Collect(1);
+
+        int agen2 = GC.GetGeneration(array);
+        int ogen2 = GC.GetGeneration(obj);
+
+        Console.WriteLine("Array is in generation: {0}", agen2);
+        Console.WriteLine("Object is in generation: {0}", ogen2);
+
+        if (agen2 > ogen2)
+        {  // gen 0,1 collected
+            Console.WriteLine("Test for GC.Collect(1) passed!");
+            return 100;
+        }
+        else if (agen2 == ogen2 && agen2 == GC.MaxGeneration)
+        {
+            // both got collected, possibly because of GC Stress
+            Console.WriteLine("Test for GC.Collect(1) passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for GC.Collect(1) failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect1.csproj b/src/coreclr/tests/src/GC/API/GC/Collect1.csproj
new file mode 100644 (file)
index 0000000..012b0e3
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Collect1.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_Default.cs b/src/coreclr/tests/src/GC/API/GC/Collect_Default.cs
new file mode 100644 (file)
index 0000000..e380b9a
--- /dev/null
@@ -0,0 +1,48 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Diagnostics;
+
+public class DefaultCollect
+{
+    public static void Usage()
+    {
+        Console.WriteLine("Usage:");
+        Console.WriteLine("{0} <0|1|2>", Process.GetCurrentProcess().ProcessName);
+    }
+
+    public static int Main(string[] args )
+    {
+
+        int gen = -1;
+        if ( (args.Length!=1) || (!Int32.TryParse(args[0], out gen)) )
+        {
+            Usage();
+            return 0;
+        }
+
+        if ( (gen < 0) || (gen>2) )
+        {
+            Usage();
+            return 0;
+        }
+
+        byte[] b = new byte[1024*1024*10];
+        int oldCollectionCount = GC.CollectionCount(gen);
+        b = null;
+
+        GC.Collect(gen, GCCollectionMode.Default);
+
+        if (GC.CollectionCount(gen)>oldCollectionCount)
+        {
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test Failed");
+        return 1;
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_Default_1.csproj b/src/coreclr/tests/src/GC/API/GC/Collect_Default_1.csproj
new file mode 100644 (file)
index 0000000..8ab65bc
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>0</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Collect_Default.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_Default_2.csproj b/src/coreclr/tests/src/GC/API/GC/Collect_Default_2.csproj
new file mode 100644 (file)
index 0000000..3b846aa
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>1</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Collect_Default.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_Default_3.csproj b/src/coreclr/tests/src/GC/API/GC/Collect_Default_3.csproj
new file mode 100644 (file)
index 0000000..4cca06b
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>2</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Collect_Default.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_Forced.cs b/src/coreclr/tests/src/GC/API/GC/Collect_Forced.cs
new file mode 100644 (file)
index 0000000..99137d5
--- /dev/null
@@ -0,0 +1,51 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Diagnostics;
+
+public class DefaultCollect
+{
+    static string ProcessName;
+
+    public static void Usage()
+    {
+        Console.WriteLine("Usage:");
+        Console.WriteLine("{0} <0|1|2>", ProcessName);
+    }
+
+    public static int Main(string[] args )
+    {
+
+        ProcessName = Process.GetCurrentProcess().ProcessName;
+        int gen = -1;
+        if ( (args.Length!=1) || (!Int32.TryParse(args[0], out gen)) )
+        {
+            Usage();
+            return 0;
+        }
+
+        if ( (gen < 0) || (gen>2) )
+        {
+            Usage();
+            return 0;
+        }
+
+        byte[] b = new byte[1024*1024*10];
+        int oldCollectionCount = GC.CollectionCount(gen);
+        b = null;
+
+        GC.Collect(gen, GCCollectionMode.Forced);
+
+        if (GC.CollectionCount(gen)>oldCollectionCount)
+        {
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test Failed");
+        return 1;
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_Forced_1.csproj b/src/coreclr/tests/src/GC/API/GC/Collect_Forced_1.csproj
new file mode 100644 (file)
index 0000000..3f3773c
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>0</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Collect_Forced.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_Forced_2.csproj b/src/coreclr/tests/src/GC/API/GC/Collect_Forced_2.csproj
new file mode 100644 (file)
index 0000000..68561ae
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>1</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Collect_Forced.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_Forced_3.csproj b/src/coreclr/tests/src/GC/API/GC/Collect_Forced_3.csproj
new file mode 100644 (file)
index 0000000..c9250a5
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>2</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Collect_Forced.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_Optimized.cs b/src/coreclr/tests/src/GC/API/GC/Collect_Optimized.cs
new file mode 100644 (file)
index 0000000..289360b
--- /dev/null
@@ -0,0 +1,69 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.IO;
+using System.Runtime;
+using System.Collections.Generic;
+using System.Diagnostics;
+
+public class OptimizedCollect
+{
+
+    public static void Usage()
+    {
+        Console.WriteLine("Usage:");
+        Console.WriteLine("{0} <0|1|2>", Process.GetCurrentProcess().ProcessName);
+    }
+
+    protected List<byte[]> b;
+    protected int collectionCount;
+    protected int newCollectionCount;
+
+
+    public void PreTest()
+    {
+        b = new List<byte[]>();
+        collectionCount = 0;
+    }
+
+    public void RunTest(int gen)
+    {
+
+        newCollectionCount = collectionCount = GC.CollectionCount(gen);
+        while (collectionCount == newCollectionCount)
+        {
+            b.Add(new byte[1024]);
+            GC.Collect(gen, GCCollectionMode.Optimized);
+            newCollectionCount = GC.CollectionCount(gen);
+        }
+
+    }
+
+
+    public static int Main(string[] args )
+    {
+
+        int gen = -1;
+        if ( (args.Length!=1) || (!Int32.TryParse(args[0], out gen)) )
+        {
+            Usage();
+            return 0;
+        }
+
+        if ( (gen < 0) || (gen>2) )
+        {
+            Usage();
+            return 0;
+        }
+
+        OptimizedCollect test = new OptimizedCollect();
+        test.PreTest();
+        test.RunTest(gen);
+
+        return 100;
+    }
+
+
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_Optimized_1.csproj b/src/coreclr/tests/src/GC/API/GC/Collect_Optimized_1.csproj
new file mode 100644 (file)
index 0000000..fde633e
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>0</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Collect_Optimized.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_Optimized_2.csproj b/src/coreclr/tests/src/GC/API/GC/Collect_Optimized_2.csproj
new file mode 100644 (file)
index 0000000..e2dcee9
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>1</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Collect_Optimized.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_Optimized_3.csproj b/src/coreclr/tests/src/GC/API/GC/Collect_Optimized_3.csproj
new file mode 100644 (file)
index 0000000..6643314
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>2</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Collect_Optimized.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_fail.cs b/src/coreclr/tests/src/GC/API/GC/Collect_fail.cs
new file mode 100644 (file)
index 0000000..6d04f18
--- /dev/null
@@ -0,0 +1,58 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/* 
+ * Tests GC.Collect(n), where n = -1...MaxGeneration+10
+ * An exception should be thrown for -1, but no other value
+ *
+ * Notes:
+ *    -passes with complus_jitminops
+ *    -passes with debug
+ *    -passes with complus_gcstress
+ */
+
+using System;
+
+public class Test
+{
+    public static int Main()
+    {
+        int[] array = new int[25];
+        bool passed = false;
+
+        try
+        {
+            GC.Collect(-1);
+        }
+        catch (ArgumentOutOfRangeException)
+        {
+            // Should throw exception
+            passed = true;
+        }
+
+        if (!passed)
+        {
+            // Exception not thrown
+            Console.WriteLine("Test for GC.Collect(-1) failed: ArgumentOutOfRangeException not thrown!");
+            return 1;
+        }
+
+        for (int i = 0; i <= GC.MaxGeneration + 10; i++)
+        {
+            try
+            {
+                GC.Collect(i); // Should not throw exception!
+            }
+            catch (ArgumentOutOfRangeException e)
+            {
+                // Exception thrown
+                Console.WriteLine("Test for GC.Collect({0}) failed: {1}", i, e.Message);
+                return 1;
+            }
+        }
+
+        Console.WriteLine("Test for GC.Collect() passed!");
+        return 100;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_fail.csproj b/src/coreclr/tests/src/GC/API/GC/Collect_fail.csproj
new file mode 100644 (file)
index 0000000..92d9711
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Collect_fail.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_neg.cs b/src/coreclr/tests/src/GC/API/GC/Collect_neg.cs
new file mode 100644 (file)
index 0000000..717d2c6
--- /dev/null
@@ -0,0 +1,36 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+public class NegCollect
+{
+    public static int Main()
+    {
+        bool retVal = true;
+        GCCollectionMode[] invalidInputs = { (GCCollectionMode)(GCCollectionMode.Default - 1), (GCCollectionMode)(GCCollectionMode.Optimized + 1) };
+
+        for (int i = 0; i < invalidInputs.Length; i++)
+        {
+            try
+            {
+                GC.Collect(2, invalidInputs[i]);
+                retVal = false;
+                Console.WriteLine("Invalid value for GC.Collect: {0}", invalidInputs[i]);
+            }
+            catch (ArgumentOutOfRangeException)
+            {
+            }
+        }
+
+        if (retVal)
+        {
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test Failed");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/Collect_neg.csproj b/src/coreclr/tests/src/GC/API/GC/Collect_neg.csproj
new file mode 100644 (file)
index 0000000..0017924
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Collect_neg.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/CollectionCountTest.cs b/src/coreclr/tests/src/GC/API/GC/CollectionCountTest.cs
new file mode 100644 (file)
index 0000000..c231c05
--- /dev/null
@@ -0,0 +1,146 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/* CollectionCountTest
+ *
+ * Tests GC.CollectionCount by passing it invalid values (<0) and
+ * values that are too large (>GC.MaxGeneration).
+ * It then tests valid values (0<=x<=GC.MaxGeneration)
+ * by making sure result is at least the number of manual collections
+ * (GC.Collect) per generation (must be at least, since the GC may collect
+ * on it's own).
+ */
+
+using System;
+
+public class CollectionCountTest
+{
+    private const int numTests = 3;
+
+    private Int32[] _negValues = { -1, -10, -10000, Int32.MinValue };
+    private Int32[] _largeValues = { GC.MaxGeneration + 1, Int32.MaxValue / 2, Int32.MaxValue - 1, Int32.MaxValue };
+
+    private CollectionCountTest()
+    {
+    }
+
+    // Checks that CollectionCount correctly counts collections to higher generations
+    public bool CollectionTest()
+    {
+        GC.Collect(2);
+        if (GC.CollectionCount(2) < 1)
+        {
+            Console.WriteLine("Failure at CollectionTest(2)");
+            return false;
+        }
+
+        GC.Collect(1);
+        if (GC.CollectionCount(1) < 2)
+        {
+            Console.WriteLine("Failure at CollectionTest(1)");
+            return false;
+        }
+
+        GC.Collect(0);
+        if (GC.CollectionCount(0) < 3)
+        {
+            Console.WriteLine("Failure at CollectionTest(0)");
+            return false;
+        }
+
+        Console.WriteLine("CollectionTest passed");
+        return true;
+    }
+
+    // Checks that CollectionCount correctly throws an exception on values < 0
+    public bool NegativeTest()
+    {
+        bool retVal = true;
+
+        foreach (int i in _negValues)
+        {
+            try
+            {
+                GC.CollectionCount(i);
+                retVal = false;
+            }
+            catch (ArgumentOutOfRangeException)
+            {
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e.Message);
+                retVal = false;
+            }
+            if (!retVal)
+            {
+                Console.WriteLine("Failure at NegativeTest");
+                break;
+            }
+        }
+
+        if (retVal)
+            Console.WriteLine("NegativeTest passed");
+        return retVal;
+    }
+
+
+    // Checks that CollectionCount returns 0 when passed 0
+    public bool LargeValuesTest()
+    {
+        bool retVal = true;
+
+        foreach (int i in _largeValues)
+        {
+            try
+            {
+                retVal = (GC.CollectionCount(i) == 0);
+                if (!retVal)
+                {
+                    Console.WriteLine("Failure at LargeValueTest: {0}", i);
+                    break;
+                }
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e.Message);
+                retVal = false;
+            }
+        }
+        if (retVal)
+            Console.WriteLine("LargeValueTest passed");
+        return retVal;
+    }
+
+
+    public bool RunTest()
+    {
+        int passedCount = 0;
+
+        if (NegativeTest())
+            passedCount++;
+        if (LargeValuesTest())
+            passedCount++;
+        if (CollectionTest())
+            passedCount++;
+
+
+        return (passedCount == numTests);
+    }
+
+
+    public static int Main()
+    {
+        CollectionCountTest test = new CollectionCountTest();
+
+        if (test.RunTest())
+        {
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test Failed");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/CollectionCountTest.csproj b/src/coreclr/tests/src/GC/API/GC/CollectionCountTest.csproj
new file mode 100644 (file)
index 0000000..c8501eb
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="CollectionCountTest.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/Finalize.cs b/src/coreclr/tests/src/GC/API/GC/Finalize.cs
new file mode 100644 (file)
index 0000000..f4fc9b9
--- /dev/null
@@ -0,0 +1,57 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests Finalize() and WaitForPendingFinalizers()
+
+using System;
+
+public class Test
+{
+    public static bool visited = false;
+    public class Dummy
+    {
+        ~Dummy()
+        {
+            Console.WriteLine("In Finalize() of Dummy");
+            Test.visited = true;
+        }
+    }
+
+    public class CreateObj
+    {
+        public Dummy obj;
+
+
+        public CreateObj()
+        {
+            obj = new Dummy();
+        }
+
+        public void RunTest()
+        {
+            obj = null;
+            GC.Collect();
+
+            GC.WaitForPendingFinalizers();  // makes sure Finalize() is called.
+        }
+    }
+
+    public static int Main()
+    {
+        CreateObj temp = new CreateObj();
+        temp.RunTest();
+
+
+        if (visited)
+        {
+            Console.WriteLine("Test for Finalize() & WaitForPendingFinalizers() passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for Finalize() & WaitForPendingFinalizers() failed!");
+            return 0;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/Finalize.csproj b/src/coreclr/tests/src/GC/API/GC/Finalize.csproj
new file mode 100644 (file)
index 0000000..6707308
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Finalize.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/GetGeneration.cs b/src/coreclr/tests/src/GC/API/GC/GetGeneration.cs
new file mode 100644 (file)
index 0000000..96be043
--- /dev/null
@@ -0,0 +1,135 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GC.GetGeneration
+
+using System;
+
+public class GetGenerationTest
+{
+    private static int s_numTests = 0;
+
+    private bool objectTest()
+    {
+        s_numTests++;
+        Object obj = new Object();
+        int g1 = GC.GetGeneration(obj);
+
+        GC.Collect();
+
+        int g2 = GC.GetGeneration(obj);
+
+        if ((g1 == g2) && (g1 == GC.MaxGeneration))
+        {
+            Console.WriteLine("GCStress is on");
+            Console.WriteLine("ObjectTest Passed!");
+            return true;
+        }
+
+        if (g1 < g2)
+        {
+            Console.WriteLine("ObjectTest Passed!");
+            return true;
+        }
+
+        Console.WriteLine("{0} {1}", g1, g2);
+        Console.WriteLine("ObjectTest Failed!");
+        return false;
+    }
+
+
+    private bool arrayTest()
+    {
+        s_numTests++;
+        int[] arr = new int[25];
+        int g1 = GC.GetGeneration(arr);
+
+        GC.Collect();
+
+        int g2 = GC.GetGeneration(arr);
+
+        if ((g1 == g2) && (g1 == GC.MaxGeneration))
+        {
+            Console.WriteLine("GCStress is on");
+            Console.WriteLine("ObjectTest Passed!");
+            return true;
+        }
+
+        if (g1 < g2)
+        {
+            Console.WriteLine("arrayTest Passed!");
+            return true;
+        }
+
+        Console.WriteLine("{0} {1}", g1, g2);
+        Console.WriteLine("arrayTest Failed!");
+        return false;
+    }
+
+
+    private bool failTest()
+    {
+        s_numTests++;
+
+        Object obj = new Object();
+        obj = null;
+
+        try
+        {
+            GC.GetGeneration(obj);
+        }
+        catch (ArgumentNullException)
+        {
+            Console.WriteLine("failTest Passed!");
+            return true;
+        }
+        catch (Exception e)
+        {
+            Console.WriteLine("Unexpected exception thrown:");
+            Console.WriteLine(e);
+        }
+
+        Console.WriteLine("failTest Failed!");
+        return false;
+    }
+
+
+    public bool RunTests()
+    {
+        int numPassed = 0;
+
+        if (objectTest())
+            numPassed++;
+
+        if (arrayTest())
+            numPassed++;
+
+        if (failTest())
+            numPassed++;
+
+
+        Console.WriteLine();
+        if (s_numTests == numPassed)
+            return true;
+
+        return false;
+    }
+
+
+
+    public static int Main()
+    {
+        GetGenerationTest t = new GetGenerationTest();
+
+        if (t.RunTests())
+        {
+            Console.WriteLine("Test for GetGeneration() passed!");
+            return 100;
+        }
+
+
+        Console.WriteLine("Test for GetGeneration() FAILED!");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/GetGeneration.csproj b/src/coreclr/tests/src/GC/API/GC/GetGeneration.csproj
new file mode 100644 (file)
index 0000000..a264121
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="GetGeneration.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/GetGenerationWR.cs b/src/coreclr/tests/src/GC/API/GC/GetGenerationWR.cs
new file mode 100644 (file)
index 0000000..e33df8f
--- /dev/null
@@ -0,0 +1,68 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+public class Dummy
+{
+    ~Dummy()
+    {
+        Console.WriteLine("In Finalize() of Dummy");
+    }
+}
+
+
+public class CreateObj
+{
+    private Dummy _obj;
+    private WeakReference _weak;
+
+    public CreateObj()
+    {
+        _obj = new Dummy();
+        _weak = new WeakReference(_obj);
+    }
+
+
+    public bool RunTest()
+    {
+        _obj = null;
+        GC.Collect();
+
+        try
+        {
+            GC.GetGeneration(_weak.Target);
+        }
+        catch (ArgumentNullException)
+        {
+            Console.WriteLine("Expected exception");
+            return true;
+        }
+        catch (Exception e)
+        {
+            Console.WriteLine("Unexpected exception: " + e);
+        }
+
+        Console.WriteLine("Expected exception not thrown!");
+        return false;
+    }
+
+
+    public static int Main()
+    {
+        CreateObj temp = new CreateObj();
+
+        if (temp.RunTest())
+        {
+            Console.WriteLine("Test passed!");
+            return 100;
+        }
+
+        Console.WriteLine("Test failed!");
+        return 1;
+    }
+}
+
+
+
diff --git a/src/coreclr/tests/src/GC/API/GC/GetGenerationWR.csproj b/src/coreclr/tests/src/GC/API/GC/GetGenerationWR.csproj
new file mode 100644 (file)
index 0000000..f058849
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="GetGenerationWR.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/GetGenerationWR2.cs b/src/coreclr/tests/src/GC/API/GC/GetGenerationWR2.cs
new file mode 100644 (file)
index 0000000..159b927
--- /dev/null
@@ -0,0 +1,58 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/********************************************************************/
+/* Test: GetGeneration
+/* Purpose: Test GC.GetGeneration() works
+/* Note: This test is not an absolute test. If it passes, it doesn't
+/* Gerantee that GetGeneration works fine, because GC.GetGeneration(Object)
+/* and GC.GetGeneration(WeakReference) may break in same way. If it failed,
+/* it needs investigation.
+/********************************************************************/
+
+namespace DefaultNamespace {
+    using System;
+
+    internal class GetGeneration
+    {
+        public static int Main( String [] str )
+        {
+            Console.Out.WriteLine("Test should return with ExitCode 100 ...");
+            Object o = new int[10];
+            WeakReference wf = new WeakReference( o );
+            bool result = false;
+
+            try
+            {
+
+                result = ( GC.GetGeneration( o ) == GC.GetGeneration( wf ));
+
+                GC.KeepAlive(o);
+
+            }
+            catch (ArgumentNullException)
+            {
+                Console.Out.WriteLine( "Caught ArgumentNullException!" );
+                result = false;
+            }
+            catch (Exception e)
+            {
+                Console.Out.WriteLine( "Caught unexpected exception!" );
+                Console.Out.WriteLine(e.Message);
+                result = false;
+            }
+
+
+            if (result)
+            {
+                Console.Out.WriteLine( "Test Passed" );
+                return 100;
+            }
+            Console.Out.WriteLine( "Test Failed" );
+
+            return 1;
+
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/GetGenerationWR2.csproj b/src/coreclr/tests/src/GC/API/GC/GetGenerationWR2.csproj
new file mode 100644 (file)
index 0000000..a22f253
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments></CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="GetGenerationWR2.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/GetGeneration_box.cs b/src/coreclr/tests/src/GC/API/GC/GetGeneration_box.cs
new file mode 100644 (file)
index 0000000..6cc0db8
--- /dev/null
@@ -0,0 +1,79 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GC.GetGeneration for boxed-parameters
+// should box parameter into an Object
+
+using System;
+
+public struct StructType {
+}
+
+public enum EnumType {
+}
+
+public class Test {
+
+    public static int Main() {
+        // literals
+        int gen = GC.GetGeneration(-1);
+        Console.WriteLine(gen);
+
+        gen = GC.GetGeneration("hello");
+        Console.WriteLine(gen);
+
+        // integral types
+        gen = GC.GetGeneration(new int());
+        Console.WriteLine(gen);
+
+        gen = GC.GetGeneration(new byte());
+        Console.WriteLine(gen);
+
+        gen = GC.GetGeneration(new sbyte());
+        Console.WriteLine(gen);
+
+        gen = GC.GetGeneration(new short());
+        Console.WriteLine(gen);
+
+        gen = GC.GetGeneration(new ushort());
+        Console.WriteLine(gen);
+
+        gen = GC.GetGeneration(new uint());
+        Console.WriteLine(gen);
+
+        gen = GC.GetGeneration(new long());
+        Console.WriteLine(gen);
+
+        gen = GC.GetGeneration(new ulong());
+        Console.WriteLine(gen);
+
+        gen = GC.GetGeneration(new char());
+        Console.WriteLine(gen);
+
+        //floating point types
+        gen = GC.GetGeneration(new float());
+        Console.WriteLine(gen);
+
+        gen = GC.GetGeneration(new double());
+        Console.WriteLine(gen);
+
+        // boolean types
+        gen = GC.GetGeneration(new bool());
+        Console.WriteLine(gen);
+
+        // other value types
+
+        gen = GC.GetGeneration(new StructType());
+        Console.WriteLine(gen);
+
+        gen = GC.GetGeneration(new EnumType());
+        Console.WriteLine(gen);
+
+        gen = GC.GetGeneration(new decimal());
+        Console.WriteLine(gen);
+
+        Console.WriteLine("Test passed");
+        return 100;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/GetGeneration_box.csproj b/src/coreclr/tests/src/GC/API/GC/GetGeneration_box.csproj
new file mode 100644 (file)
index 0000000..4e686f3
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments></CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="GetGeneration_box.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/GetGeneration_fail.cs b/src/coreclr/tests/src/GC/API/GC/GetGeneration_fail.cs
new file mode 100644 (file)
index 0000000..40cf4d2
--- /dev/null
@@ -0,0 +1,40 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GC.GetGeneration(null)..should throw exception: System.ArgumentNullException
+
+using System;
+
+public class Test
+{
+    public static int Main()
+    {
+        Object obj1 = new Object();
+
+        Console.WriteLine("This test should throw an exception!");
+        Console.WriteLine("Generation: " + GC.GetGeneration(obj1));
+
+        int[] array = new int[25];
+        array = null;
+
+        try
+        {
+            Console.WriteLine("Generation: " + GC.GetGeneration(array));
+        }
+        catch (ArgumentNullException e)
+        {
+            Console.WriteLine("Expected exception thrown: {0}", e);
+            Console.WriteLine("Test for GetGeneration() passed!");
+            return 100;
+        }
+        catch (Exception e)
+        {
+            Console.WriteLine("Unexpected exception thrown:");
+            Console.WriteLine(e);
+        }
+
+        Console.WriteLine("Test for GetGeneration() failed!");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/GetGeneration_fail.csproj b/src/coreclr/tests/src/GC/API/GC/GetGeneration_fail.csproj
new file mode 100644 (file)
index 0000000..34810f5
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments></CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="GetGeneration_fail.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/GetTotalMemory.cs b/src/coreclr/tests/src/GC/API/GC/GetTotalMemory.cs
new file mode 100644 (file)
index 0000000..eedafab
--- /dev/null
@@ -0,0 +1,76 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace DefaultNamespace {
+    using System;
+
+    internal class GetTotalMemory
+    {
+        // margin of error, since GetTotalMemory is an approximation
+        // a discrepancy of more than 50 bytes should be investigated
+        public const int padding = 50;
+
+        public static int Main(String [] args )
+        {
+
+            int MB = 1024*1024;
+            int iRep = 0;
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            if (args.Length==0)
+            {
+                iRep = 10;
+            }
+            else if (args.Length == 1)
+            {
+                if (!Int32.TryParse( args[0], out iRep ))
+                {
+                    iRep = 10;
+                }
+            }
+            else
+            {
+                Console.WriteLine("usage: GetTotalMemory arg, good arg range is 5--50. Default value is 10." );
+                return 1;
+            }
+
+            // clean up memory before measuring
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            long heapSizeBeforeAlloc = GC.GetTotalMemory(false);
+
+            Console.WriteLine( "HeapSize before allocating any memory: {0}", heapSizeBeforeAlloc );
+
+            byte[] bary = new byte[1];
+            for(int i=1; i<=iRep; i++ )
+            {
+                bary = new byte[i*MB];  //allocate iMB memory
+                bary[0] = 1;
+                bary[i*MB-1] = 1;
+
+                long heapSizeAfterAlloc = GC.GetTotalMemory(false);
+                Console.WriteLine( "HeapSize after allocated {0} MB memory: {1}", i, heapSizeAfterAlloc);
+                if( (heapSizeAfterAlloc - heapSizeBeforeAlloc)+i*padding<= i*MB || (heapSizeAfterAlloc - heapSizeBeforeAlloc) > (i+1)*MB )
+                {
+                    Console.WriteLine( "Test Failed" );
+                    return 1;
+                }
+                bary[0] = 2;
+                bary[i*MB-1] = 2;
+                bary = null;
+
+                GC.Collect();
+                GC.WaitForPendingFinalizers();
+
+                heapSizeBeforeAlloc = GC.GetTotalMemory(false);
+                Console.WriteLine( "HeapSize after delete all objects: {0}", heapSizeBeforeAlloc );
+
+            }
+
+            Console.WriteLine( "Test Passed!" );
+            return 100;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/GetTotalMemory.csproj b/src/coreclr/tests/src/GC/API/GC/GetTotalMemory.csproj
new file mode 100644 (file)
index 0000000..be0d4dc
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments></CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="GetTotalMemory.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/KeepAlive.cs b/src/coreclr/tests/src/GC/API/GC/KeepAlive.cs
new file mode 100644 (file)
index 0000000..df3d9d2
--- /dev/null
@@ -0,0 +1,84 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/* 
+ * Tests GC.KeepAlive(obj), where obj is the Object reference whose
+ * finalizer you don't want called until after the call to KeepAlive.
+ *
+ * Changes:
+ *   -Added Dummy2 object whose finalizer should get called for comparison
+ *
+ * Notes:
+ *   - passes with complus_jitminops set*
+ *   - passes with complus_gcstress = 0,1,2,3,4
+ *   - passes in debug mode
+ */
+
+using System;
+
+public class Test
+{
+    public static bool visited1 = false;
+    public static bool visited2 = false;
+
+
+    public class Dummy
+    {
+        ~Dummy()
+        {
+            // this finalizer should not get called until after
+            // the call to GC.KeepAlive(obj)
+            Console.WriteLine("In Finalize() of Dummy");
+            visited1 = true;
+        }
+    }
+
+
+    public class Dummy2
+    {
+        ~Dummy2()
+        {
+            // this finalizer should get called after
+            // the call to GC.WaitForPendingFinalizers()
+            Console.WriteLine("In Finalize() of Dummy2");
+            visited2 = true;
+        }
+    }
+
+
+    public static void RunTest()
+    {
+        Dummy obj = new Dummy();
+        Dummy2 obj2 = new Dummy2();
+
+        // *uncomment the for loop to make test fail with complus_jitminops set
+        // by design as per briansul
+
+        //for (int i=0; i<5; i++) {
+        obj2 = null;
+        GC.Collect();
+        GC.WaitForPendingFinalizers();
+        //}
+
+        GC.KeepAlive(obj);  // will keep obj alive until this point
+    }
+
+    public static int Main()
+    {
+        RunTest();
+
+        if ((visited1 == false) && (visited2 == true))
+        {
+            Console.WriteLine("Test for KeepAlive() passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for KeepAlive() failed!");
+
+
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/KeepAlive.csproj b/src/coreclr/tests/src/GC/API/GC/KeepAlive.csproj
new file mode 100644 (file)
index 0000000..dd6c0ea
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="KeepAlive.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/KeepAliveNull.cs b/src/coreclr/tests/src/GC/API/GC/KeepAliveNull.cs
new file mode 100644 (file)
index 0000000..2091a1b
--- /dev/null
@@ -0,0 +1,56 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests KeepAlive()
+
+using System;
+
+public class Test
+{
+    public static bool visited;
+    public class Dummy
+    {
+        ~Dummy()
+        {
+            Console.WriteLine("In Finalize() of Dummy");
+            visited = true;
+        }
+    }
+
+    public class CreateObj
+    {
+        public Dummy obj;
+
+        public CreateObj()
+        {
+            obj = new Dummy();
+        }
+
+        public void RunTest()
+        {
+            obj = null;     // this will collect the obj even if we have KeepAlive()           
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            GC.KeepAlive(obj);  // will keep alive 'obj' till this point
+        }
+    }
+
+    public static int Main()
+    {
+        CreateObj temp = new CreateObj();
+        temp.RunTest();
+
+        if (visited)
+        {
+            Console.WriteLine("Test for KeepAlive() passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for KeepAlive() failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/KeepAliveNull.csproj b/src/coreclr/tests/src/GC/API/GC/KeepAliveNull.csproj
new file mode 100644 (file)
index 0000000..8ae4315
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="KeepAliveNull.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/KeepAliveRecur.cs b/src/coreclr/tests/src/GC/API/GC/KeepAliveRecur.cs
new file mode 100644 (file)
index 0000000..abe28d5
--- /dev/null
@@ -0,0 +1,55 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests KeepAlive() in Recursive method
+
+using System;
+
+public class Test
+{
+    public class Dummy
+    {
+        public static bool visited;
+        ~Dummy()
+        {
+            Console.WriteLine("In Finalize() of Dummy");
+            visited = true;
+        }
+    }
+
+    public static int count;
+
+    public static void foo(Object o)
+    {
+        if (count == 10) return;
+        Console.WriteLine("Count: {0}", count);
+        count++;
+
+        GC.Collect();
+        GC.WaitForPendingFinalizers();
+
+        foo(o);     //Recursive call
+
+        GC.KeepAlive(o);    // Keeping object alive 
+    }
+
+    public static int Main()
+    {
+        Dummy obj = new Dummy();
+
+        foo(obj);
+        Console.WriteLine("After call to foo()");
+
+        if (Dummy.visited == false)
+        {  // has not visited the Finalize()
+            Console.WriteLine("Test for KeepAlive() recursively passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for KeepAlive() recursively failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/KeepAliveRecur.csproj b/src/coreclr/tests/src/GC/API/GC/KeepAliveRecur.csproj
new file mode 100644 (file)
index 0000000..f3a09ec
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="KeepAliveRecur.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/MaxGeneration.cs b/src/coreclr/tests/src/GC/API/GC/MaxGeneration.cs
new file mode 100644 (file)
index 0000000..d8e8f68
--- /dev/null
@@ -0,0 +1,29 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GC.MaxGeneration
+
+using System;
+
+public class Test {
+       public static int Main() {
+                               
+               for(int i=0;i<1000;i++) {
+               Object[] array = new Object[i];
+               }
+               
+               Console.WriteLine("Max Generations: " + GC.MaxGeneration);
+               if(GC.MaxGeneration == 2) {
+                       Console.WriteLine("Test for GC.MaxGeneration passed!");
+            return 100;
+               }
+               else {
+                       Console.WriteLine("Test for GC.MaxGeneration failed!");
+            return 1;
+               }
+               
+               }
+
+       }
+
diff --git a/src/coreclr/tests/src/GC/API/GC/MaxGeneration.csproj b/src/coreclr/tests/src/GC/API/GC/MaxGeneration.csproj
new file mode 100644 (file)
index 0000000..c9e83e0
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments></CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="MaxGeneration.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/ReRegisterForFinalize.cs b/src/coreclr/tests/src/GC/API/GC/ReRegisterForFinalize.cs
new file mode 100644 (file)
index 0000000..889e162
--- /dev/null
@@ -0,0 +1,67 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests ReRegisterForFinalize()
+
+using System;
+
+public class Test {
+
+    public class Dummy {
+        
+        public static int flag;
+        ~Dummy() {
+            Console.WriteLine("In Finalize() of Dummy");    
+            if(flag == 0) flag=1;  // one object has visited;
+            else flag=0; //error-- both objects have visited
+        }
+    }
+
+    public class CreateObj{
+        Dummy obj1;
+        Dummy obj2;
+
+        public CreateObj() {
+            obj1 = new Dummy();
+            obj2 = new Dummy();
+
+             
+            GC.SuppressFinalize(obj1);    // should not call the Finalize() for obj1
+            GC.SuppressFinalize(obj2);    // should not call the Finalize() for obj2
+        }
+
+        public bool RunTest() {
+            
+            GC.ReRegisterForFinalize(obj1); // should call Finalize() for obj1 now.
+        
+            obj1=null;
+            obj2=null;
+
+            GC.Collect();
+        
+            GC.WaitForPendingFinalizers();   // call all Finalizers.
+
+            if(Dummy.flag==1) {
+                return true;
+            }
+            else {
+                return false;
+            }
+        }
+        
+    }
+    public static int Main() {
+        CreateObj temp = new CreateObj();
+        bool passed = temp.RunTest();
+    
+        if(passed) {
+            Console.WriteLine("Test for ReRegisterForFinalize() passed!");
+            return 100;
+        }
+        else {
+            Console.WriteLine("Test for ReRegisterForFinalize() failed!");
+            return 1;    
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/ReRegisterForFinalize.csproj b/src/coreclr/tests/src/GC/API/GC/ReRegisterForFinalize.csproj
new file mode 100644 (file)
index 0000000..6db3912
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments></CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="ReRegisterForFinalize.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/ReRegisterForFinalize_null.cs b/src/coreclr/tests/src/GC/API/GC/ReRegisterForFinalize_null.cs
new file mode 100644 (file)
index 0000000..06f4e08
--- /dev/null
@@ -0,0 +1,42 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests ReRegisterForFinalize()
+
+using System;
+
+public class Test
+{
+    public bool RunTest()
+    {
+        try
+        {
+            GC.ReRegisterForFinalize(null); // should call Finalize() for obj1 now.
+        }
+        catch (ArgumentNullException)
+        {
+            return true;
+        }
+        catch (Exception)
+        {
+            Console.WriteLine("Unexpected Exception!");
+        }
+
+        return false;
+    }
+
+
+    public static int Main()
+    {
+        Test t = new Test();
+        if (t.RunTest())
+        {
+            Console.WriteLine("Null Test for ReRegisterForFinalize() passed!");
+            return 100;
+        }
+
+        Console.WriteLine("Null Test for ReRegisterForFinalize() failed!");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/ReRegisterForFinalize_null.csproj b/src/coreclr/tests/src/GC/API/GC/ReRegisterForFinalize_null.csproj
new file mode 100644 (file)
index 0000000..6580c09
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="ReRegisterForFinalize_null.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/RemoveMemoryPressureTest.cs b/src/coreclr/tests/src/GC/API/GC/RemoveMemoryPressureTest.cs
new file mode 100644 (file)
index 0000000..e288efb
--- /dev/null
@@ -0,0 +1,132 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/* RemoveMemoryPressureTest
+ *
+ * Tests GC.RemoveMemoryPressure by passing it values that are too small (<=0) and
+ * values that are too large (>Int32.MaxValue on 32-bit).
+ */
+
+
+using System;
+using System.Diagnostics;
+using System.Security;
+using System.Runtime.InteropServices;
+
+public class RemoveMemoryPressureTest
+{
+    public int TestCount = 0;
+
+    private long[] _negValues = { 0, -1, Int32.MinValue - (long)1, Int64.MinValue / (long)2, Int64.MinValue };
+    private long[] _largeValues = { Int32.MaxValue + (long)1, Int64.MaxValue };
+
+
+    private RemoveMemoryPressureTest()
+    {
+    }
+
+
+    public bool TooSmallTest()
+    {
+        TestCount++;
+        bool retVal = true;
+
+        foreach (long i in _negValues)
+        {
+            try
+            {
+                GC.RemoveMemoryPressure(i);
+                Console.WriteLine("Failure at TooSmallTest: {0}", i);
+                retVal = false;
+                break;
+            }
+            catch (ArgumentOutOfRangeException)
+            {
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e.Message);
+                Console.WriteLine("Failure at TooSmallTest: {0}", i);
+                retVal = false;
+                break;
+            }
+        }
+
+        if (retVal)
+            Console.WriteLine("TooSmallTest Passed");
+        return retVal;
+    }
+
+
+    public bool TooLargeTest()
+    {
+        TestCount++;
+
+        bool retVal = true;
+
+        foreach (long i in _largeValues)
+        {
+            try
+            {
+                GC.RemoveMemoryPressure(i);
+                // this should throw exception on 32-bit
+                if (IntPtr.Size == Marshal.SizeOf(new Int32()))
+                {
+                    Console.WriteLine("Failure at LargeValueTest: {0}", i);
+                    retVal = false;
+                    break;
+                }
+            }
+            catch (ArgumentOutOfRangeException)
+            {
+                // this should not throw exception on 64-bit
+                if (IntPtr.Size == Marshal.SizeOf(new Int64()))
+                {
+                    Console.WriteLine("Failure at LargeValueTest: {0}", i);
+                    retVal = false;
+                    break;
+                }
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e.Message);
+                retVal = false;
+                break;
+            }
+        }
+
+        if (retVal)
+            Console.WriteLine("TooLargeTest Passed");
+        return retVal;
+    }
+
+
+    public bool RunTest()
+    {
+        int passCount = 0;
+
+        if (TooSmallTest())
+            passCount++;
+
+        if (TooLargeTest())
+            passCount++;
+
+        return (passCount == TestCount);
+    }
+
+
+    public static int Main()
+    {
+        RemoveMemoryPressureTest test = new RemoveMemoryPressureTest();
+
+        if (test.RunTest())
+        {
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test Failed");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/RemoveMemoryPressureTest.csproj b/src/coreclr/tests/src/GC/API/GC/RemoveMemoryPressureTest.csproj
new file mode 100644 (file)
index 0000000..81fecea
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="RemoveMemoryPressureTest.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/RemoveUsageTest.cs b/src/coreclr/tests/src/GC/API/GC/RemoveUsageTest.cs
new file mode 100644 (file)
index 0000000..4087d89
--- /dev/null
@@ -0,0 +1,114 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/* RemoveUsageTest
+ *
+ * Tests GC.RemoveMemoryPressure by passing a valid value (RemoveMemoryPressureTest.Pressure)
+ * and making sure the objects with Removed pressure get collected less times by
+ * the GC than those with pressure.
+ */
+
+
+using System;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+
+public class Dummy
+{
+    private long _pressure;
+
+    public Dummy(long pressure)
+    {
+        _pressure = pressure;
+        GC.AddMemoryPressure(pressure);
+    }
+
+    public Dummy() { }
+
+    ~Dummy()
+    {
+        if (_pressure > 0)
+            GC.RemoveMemoryPressure(_pressure);
+    }
+}
+
+
+public class RemoveUsageTest
+{
+    public static int Pressure = 100000; // test will fail with values less than this
+    private int _numTests = 0;
+
+    private RemoveUsageTest()
+    {
+    }
+
+
+    public bool RemoveTest()
+    {
+        _numTests++;
+
+        int gcCount1 = GC.CollectionCount(0);
+        for (int i = 0; i < 100; i++)
+        {
+            Dummy heavy = new Dummy(RemoveUsageTest.Pressure);
+            int gen = GC.GetGeneration(heavy);
+            if (gen != 0)
+            {
+                Console.WriteLine("Warning: newly-allocated dummy ended up in gen {0}", gen);
+            }
+            GC.WaitForPendingFinalizers();
+        }
+        gcCount1 = GC.CollectionCount(0) - gcCount1;
+
+
+        int gcCount2 = GC.CollectionCount(0);
+        for (int i = 0; i < 100; i++)
+        {
+            Dummy light = new Dummy();
+            int gen = GC.GetGeneration(light);
+            if (gen != 0)
+            {
+                Console.WriteLine("Warning: newly-allocated dummy ended up in gen {0}", gen);
+            }
+            GC.WaitForPendingFinalizers();
+        }
+        gcCount2 = GC.CollectionCount(0) - gcCount2;
+
+        Console.WriteLine("{0} {1}", gcCount1, gcCount2);
+        if (gcCount1 > gcCount2)
+        {
+            Console.WriteLine("RemoveTest Passed");
+            Console.WriteLine();
+            return true;
+        }
+
+        Console.WriteLine("RemoveTest Failed");
+        Console.WriteLine();
+        return false;
+    }
+
+    public bool RunTest()
+    {
+        int numPass = 0;
+
+        if (RemoveTest())
+            numPass++;
+
+        return (numPass == _numTests);
+    }
+
+    public static int Main()
+    {
+        RemoveUsageTest test = new RemoveUsageTest();
+
+        if (test.RunTest())
+        {
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test Failed");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/RemoveUsageTest.csproj b/src/coreclr/tests/src/GC/API/GC/RemoveUsageTest.csproj
new file mode 100644 (file)
index 0000000..b3a8abb
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="RemoveUsageTest.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/SuppressFinalize.cs b/src/coreclr/tests/src/GC/API/GC/SuppressFinalize.cs
new file mode 100644 (file)
index 0000000..b8c3aa8
--- /dev/null
@@ -0,0 +1,40 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests SuppressFinalize()
+
+using System;
+
+public class Test {
+
+       public class Dummy {
+
+               public static bool visited;
+               ~Dummy() {
+                       Console.WriteLine("In Finalize() of Dummy");    
+                       visited=true;
+               }
+       }
+
+       public static int Main() {
+
+               Dummy obj1 = new Dummy();
+       
+               GC.SuppressFinalize(obj1);      // should not call the Finalizer() for obj1
+               obj1=null;
+                       
+               GC.Collect();
+               
+               GC.WaitForPendingFinalizers();   // call all Finalizers.
+
+               if(Dummy.visited == false) {
+                       Console.WriteLine("Test for SuppressFinalize() passed!");
+            return 100;
+               }
+               else {
+                       Console.WriteLine("Test for SuppressFinalize() failed!");
+            return 1;
+               }
+       }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/SuppressFinalize.csproj b/src/coreclr/tests/src/GC/API/GC/SuppressFinalize.csproj
new file mode 100644 (file)
index 0000000..5c1c8bf
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments></CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="SuppressFinalize.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/SuppressFinalize_Null.cs b/src/coreclr/tests/src/GC/API/GC/SuppressFinalize_Null.cs
new file mode 100644 (file)
index 0000000..8986e15
--- /dev/null
@@ -0,0 +1,42 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests SuppressFinalize()
+
+using System;
+
+public class Test
+{
+    public bool RunTest()
+    {
+        try
+        {
+            GC.SuppressFinalize(null);  // should not call the Finalizer() for obj1
+        }
+        catch (ArgumentNullException)
+        {
+            return true;
+        }
+        catch (Exception)
+        {
+            Console.WriteLine("Unexpected Exception!");
+        }
+
+        return false;
+    }
+
+
+    public static int Main()
+    {
+        Test t = new Test();
+        if (t.RunTest())
+        {
+            Console.WriteLine("Null test for SuppressFinalize() passed!");
+            return 100;
+        }
+
+        Console.WriteLine("Null test for SuppressFinalize() failed!");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/SuppressFinalize_Null.csproj b/src/coreclr/tests/src/GC/API/GC/SuppressFinalize_Null.csproj
new file mode 100644 (file)
index 0000000..24c1884
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="SuppressFinalize_Null.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/TotalMemory.cs b/src/coreclr/tests/src/GC/API/GC/TotalMemory.cs
new file mode 100644 (file)
index 0000000..ad53846
--- /dev/null
@@ -0,0 +1,37 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GC.TotalMemory
+
+using System;
+
+public class Test {
+
+    public static int Main() {
+
+        GC.Collect();
+        GC.Collect();
+
+        int[] array1 = new int[20000];
+        int memold = (int) GC.GetTotalMemory(false);
+        Console.WriteLine("Total Memory: " + memold);
+        
+        array1=null;
+        GC.Collect();
+        
+        int[] array2 = new int[40000];
+        int memnew = (int) GC.GetTotalMemory(false);
+        Console.WriteLine("Total Memory: " + memnew);
+
+        if(memnew >= memold) {
+            Console.WriteLine("Test for GC.TotalMemory passed!");
+            return 100;
+        }
+        else {
+            Console.WriteLine("Test for GC.TotalMemory failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GC/TotalMemory.csproj b/src/coreclr/tests/src/GC/API/GC/TotalMemory.csproj
new file mode 100644 (file)
index 0000000..b9d5f0a
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments></CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="TotalMemory.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/TotalMemory2.cs b/src/coreclr/tests/src/GC/API/GC/TotalMemory2.cs
new file mode 100644 (file)
index 0000000..71f16f3
--- /dev/null
@@ -0,0 +1,45 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GC.TotalMemory
+
+using System;
+
+public class Test
+{
+    public static int Main()
+    {
+        GC.Collect();
+        GC.Collect();
+
+        int[] array1 = new int[20000];
+        int memold = (int)GC.GetTotalMemory(false);
+        Console.WriteLine("Total Memory: " + memold);
+
+        array1 = null;
+
+        int before = GC.CollectionCount(2);
+        Console.WriteLine("# Collections " + before);
+        int[] array2 = new int[40000];
+        int memnew = (int)GC.GetTotalMemory(true);
+        Console.WriteLine("Total Memory: " + memnew);
+        int after = GC.CollectionCount(2);
+        Console.WriteLine("# Collections " + after);
+
+        GC.KeepAlive(array2);
+
+
+        if ((before < after) && (memnew > memold))
+        {
+            Console.WriteLine("Test for GC.TotalMemory passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for GC.TotalMemory failed!");
+            return 1;
+        }
+    }
+}
+
diff --git a/src/coreclr/tests/src/GC/API/GC/TotalMemory2.csproj b/src/coreclr/tests/src/GC/API/GC/TotalMemory2.csproj
new file mode 100644 (file)
index 0000000..fe90973
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="TotalMemory2.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GC/app.config b/src/coreclr/tests/src/GC/API/GC/app.config
new file mode 100644 (file)
index 0000000..6f7bbd9
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/AddrOfPinnedObject.cs b/src/coreclr/tests/src/GC/API/GCHandle/AddrOfPinnedObject.cs
new file mode 100644 (file)
index 0000000..caf43ec
--- /dev/null
@@ -0,0 +1,37 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GCHandle.AddrOfPinnedObject() .. The address of a pinned object remains same even after a collection
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test
+{
+    public static int Main()
+    {
+        int[] array = new int[25];
+
+        Console.WriteLine("Allocating a pinned handle to object..");
+        GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned);  // pinned this object.
+
+        IntPtr addr1 = handle.AddrOfPinnedObject();
+        Console.WriteLine("AddrOfPinnedObject = {0}", addr1);
+
+        GC.Collect();
+        IntPtr addr2 = handle.AddrOfPinnedObject();
+        Console.WriteLine("After Collection AddrOfPinnedObject = {0}", addr2);
+
+        if (addr1 == addr2)
+        {
+            Console.WriteLine("Test for GCHandle.AddrOfPinnedObject() passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for GCHandle.AddrOfPinnedObject() failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/AddrOfPinnedObject.csproj b/src/coreclr/tests/src/GC/API/GCHandle/AddrOfPinnedObject.csproj
new file mode 100644 (file)
index 0000000..f5d9093
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="AddrOfPinnedObject.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/AddrOfPinnedObject_neg.cs b/src/coreclr/tests/src/GC/API/GCHandle/AddrOfPinnedObject_neg.cs
new file mode 100644 (file)
index 0000000..9af56b6
--- /dev/null
@@ -0,0 +1,64 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Negative Test for GCHandle.AddrOfPinnedObject()...should throw and exception when handle is not pinned.
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test
+{
+    public static int Main()
+    {
+        int[] array = new int[25];
+        bool passed = true;
+
+        Console.WriteLine("Allocating a normal handle to object..");
+        GCHandle handle = GCHandle.Alloc(array);  // handle is NOT pinned.
+
+        try
+        {
+            IntPtr addr = handle.AddrOfPinnedObject();
+            Console.WriteLine("AddrOfPinnedObject = {0}", addr);
+        }
+        catch (InvalidOperationException)
+        {
+            Console.WriteLine("Caught expected exception");
+        }
+        catch (Exception)
+        {
+            Console.WriteLine("Caught unexpected exception!");
+            Console.WriteLine("Test1 Failed!");
+            passed = false;
+        }
+
+        handle.Free();
+
+        try
+        {
+            IntPtr addr = handle.AddrOfPinnedObject();
+            Console.WriteLine("AddrOfPinnedObject = {0}", addr);
+        }
+        catch (InvalidOperationException)
+        {
+            Console.WriteLine("Caught expected exception");
+        }
+        catch (Exception)
+        {
+            Console.WriteLine("Caught unexpected exception!");
+            Console.WriteLine("Test1 Failed!");
+            passed = false;
+        }
+
+
+        if (!passed)
+        {
+            Console.WriteLine("Test Failed!");
+            return 1;
+        }
+
+        Console.WriteLine("Test Passed!");
+        return 100;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/AddrOfPinnedObject_neg.csproj b/src/coreclr/tests/src/GC/API/GCHandle/AddrOfPinnedObject_neg.csproj
new file mode 100644 (file)
index 0000000..aaa378b
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="AddrOfPinnedObject_neg.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Alloc.cs b/src/coreclr/tests/src/GC/API/GCHandle/Alloc.cs
new file mode 100644 (file)
index 0000000..a0c7b4a
--- /dev/null
@@ -0,0 +1,34 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GCHandle.Alloc()
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test
+{
+    public static int Main()
+    {
+        int[] array = new int[25];
+
+        Console.WriteLine("Allocating a handle to object..");
+        GCHandle handle = GCHandle.Alloc(array);
+
+        bool ans = handle.IsAllocated;
+        if (ans)
+            Console.WriteLine("GCHandle is allocated = ");
+
+        if (ans == true)
+        {
+            Console.WriteLine("Test for GCHandle.Alloc() passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for GCHandle.Alloc() failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Alloc.csproj b/src/coreclr/tests/src/GC/API/GCHandle/Alloc.csproj
new file mode 100644 (file)
index 0000000..78f3eb2
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Alloc.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Alloc_neg.cs b/src/coreclr/tests/src/GC/API/GCHandle/Alloc_neg.cs
new file mode 100644 (file)
index 0000000..c082540
--- /dev/null
@@ -0,0 +1,40 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Negative Test for GCHandle.Alloc() .. trying to allocated a handle to a null object.
+
+/*************************************************************************************
+ This is allowed because Pinning happens whenever a GC occurs. So if a GC occurs and 
+ there is an object in the handle, we will pin it. It is quite reasonable to create
+ the handle now and fill in the object later.
+**************************************************************************************/
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test
+{
+    public static int Main()
+    {
+        int[] array = new int[25];
+        array = null;
+
+        GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned);
+
+        bool ans = handle.IsAllocated;
+        if (ans)
+            Console.WriteLine("GCHandle is allocated = ");
+
+        if (ans == true)
+        {
+            Console.WriteLine("Negative test for GCHandle.Alloc() passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Negative test for GCHandle.Alloc() failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Alloc_neg.csproj b/src/coreclr/tests/src/GC/API/GCHandle/Alloc_neg.csproj
new file mode 100644 (file)
index 0000000..240d059
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Alloc_neg.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Alloc_neg2.cs b/src/coreclr/tests/src/GC/API/GCHandle/Alloc_neg2.cs
new file mode 100644 (file)
index 0000000..d9615a8
--- /dev/null
@@ -0,0 +1,57 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*
+This test verifies GCHandle.Alloc's ability to validate bad GCHandleTypes, since any int can be cast as a GCHandleType
+*/
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test
+{
+    public static int Main()
+    {
+        // The third element needs to be updated if Pinned is no longer the last value in the GCHandleType enum
+        long[] invalidValues = { Int32.MinValue, -1, (long)(GCHandleType.Pinned + 1), Int32.MaxValue, UInt32.MaxValue, Int64.MaxValue };
+        bool passed = true;
+
+        for (int i = 0; i < invalidValues.Length; i++)
+        {
+            // GCHandle.Alloc internally casts the GCHandleType to a uint
+            Console.WriteLine("Input: {0}, Converted to: {1}", invalidValues[i], (uint)invalidValues[i]);
+
+            GCHandle gch = new GCHandle();
+            try
+            {
+                gch = GCHandle.Alloc(new object(), (GCHandleType)(invalidValues[i]));
+                Console.WriteLine("Failed");
+                passed = false;
+                gch.Free();
+            }
+            catch (ArgumentOutOfRangeException)
+            {
+                // caught the expected exception
+                Console.WriteLine("Passed");
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine("Caught unexpected exception");
+                Console.WriteLine(e);
+                passed = false;
+            }
+
+            Console.WriteLine();
+        }
+
+        if (passed)
+        {
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test Failed");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Alloc_neg2.csproj b/src/coreclr/tests/src/GC/API/GCHandle/Alloc_neg2.csproj
new file mode 100644 (file)
index 0000000..8f25120
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Alloc_neg2.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Casting.cs b/src/coreclr/tests/src/GC/API/GCHandle/Casting.cs
new file mode 100644 (file)
index 0000000..94f8c40
--- /dev/null
@@ -0,0 +1,125 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*
+ * TEST:        Casting
+ * DESCRIPTION: Tests casting to and from IntPtrs.
+ *              See also ToFromIntPtr.cs test.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Dummy
+{
+    public Dummy(int i)
+    {
+        this.i = i;
+    }
+    public int i;
+}
+
+
+public class CastingTest
+{
+    private int _numTests = 0;
+
+    private bool CastTest()
+    {
+        _numTests++;
+
+        int dummyValue = 101;
+
+        GCHandle gch = GCHandle.Alloc(new Dummy(dummyValue));
+        GCHandle gch2 = (GCHandle)((IntPtr)gch);
+        if (gch.Target == gch2.Target)
+        {
+            Console.WriteLine("CastTest Passed");
+            return true;
+        }
+
+        Console.WriteLine("CastTest Failed");
+        return false;
+    }
+
+
+    private bool FromZeroTest()
+    {
+        _numTests++;
+        try
+        {
+            GCHandle gch3 = (GCHandle)IntPtr.Zero;
+        }
+        catch (InvalidOperationException)
+        {
+            Console.WriteLine("FromZeroTest Passed");
+            return true;
+        }
+        catch (Exception)
+        {
+            Console.WriteLine("Unexpected Exception:");
+        }
+
+        Console.WriteLine("FromZeroTest Failed");
+        return false;
+    }
+
+
+    private bool ToZeroTest()
+    {
+        _numTests++;
+
+        GCHandle gch = GCHandle.Alloc(new Dummy(99));
+        gch.Free();
+        IntPtr intPtr = (IntPtr)gch;
+
+        if (intPtr == IntPtr.Zero)
+        {
+            Console.WriteLine("ToZeroTest Passed");
+            return true;
+        }
+
+        Console.WriteLine("ToZeroTest Failed");
+        return false;
+    }
+
+
+    public bool RunTests()
+    {
+        int numPassed = 0;
+
+        if (CastTest())
+        {
+            numPassed++;
+        }
+
+        if (ToZeroTest())
+        {
+            numPassed++;
+        }
+
+        if (FromZeroTest())
+        {
+            numPassed++;
+        }
+
+        Console.WriteLine();
+        return (_numTests == numPassed);
+    }
+
+
+    public static int Main()
+    {
+        CastingTest t = new CastingTest();
+
+        if (t.RunTests())
+        {
+            Console.WriteLine("CastingTest Passed!");
+            return 100;
+        }
+
+        Console.WriteLine("CastingTest Failed!");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Casting.csproj b/src/coreclr/tests/src/GC/API/GCHandle/Casting.csproj
new file mode 100644 (file)
index 0000000..e603c12
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Casting.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Equality.cs b/src/coreclr/tests/src/GC/API/GCHandle/Equality.cs
new file mode 100644 (file)
index 0000000..eb91658
--- /dev/null
@@ -0,0 +1,99 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Equality
+{
+    public bool RunTest()
+    {
+        Object o = new Object();
+        GCHandle gc = GCHandle.Alloc(o);
+        GCHandle gc2 = GCHandle.Alloc(o);
+        GCHandle gc3 = gc;
+
+        if (gc.Equals(null))
+        {
+            Console.WriteLine("Equals null failed");
+            return false;
+        }
+
+        if (gc.Equals(new Object()))
+        {
+            Console.WriteLine("Equals new Object failed");
+            return false;
+        }
+
+        if (gc.Equals(gc2))
+        {
+            Console.WriteLine("Equals GCHandle 1 failed");
+            return false;
+        }
+
+        if (!gc.Equals(gc3))
+        {
+            Console.WriteLine("Equals GCHandle 2 failed");
+            return false;
+        }
+
+
+        if (gc == gc2)
+        {
+            Console.WriteLine("== GCHandle 1 failed");
+            return false;
+        }
+
+        if (!(gc == gc3))
+        {
+            Console.WriteLine("== GCHandle 2 failed");
+            return false;
+        }
+
+        if (gc.GetHashCode() == gc2.GetHashCode())
+        {
+            Console.WriteLine("GetHashCode 1 failed");
+            return false;
+        }
+
+        if (gc.GetHashCode() != gc3.GetHashCode())
+        {
+            Console.WriteLine("GetHashCode 2 failed");
+            return false;
+        }
+
+
+        if (!(gc != gc2))
+        {
+            Console.WriteLine("!= GCHandle 1 failed");
+            return false;
+        }
+
+        if (gc != gc3)
+        {
+            Console.WriteLine("!= GCHandle 2 failed");
+            return false;
+        }
+
+        return true;
+    }
+
+
+    public static int Main()
+    {
+        Equality e = new Equality();
+
+
+        if (e.RunTest())
+        {
+            Console.WriteLine();
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+
+        Console.WriteLine();
+        Console.WriteLine("Test Failed");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Equality.csproj b/src/coreclr/tests/src/GC/API/GCHandle/Equality.csproj
new file mode 100644 (file)
index 0000000..95ff272
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Equality.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Free.cs b/src/coreclr/tests/src/GC/API/GCHandle/Free.cs
new file mode 100644 (file)
index 0000000..97ae4e5
--- /dev/null
@@ -0,0 +1,37 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GCHandle.Free()
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test
+{
+    public static int Main()
+    {
+        int[] array = new int[25];
+
+        Console.WriteLine("Allocating a handle to object..");
+        GCHandle handle = GCHandle.Alloc(array);
+
+        Console.WriteLine("Freeing the handle...");
+        handle.Free();
+
+        bool ans = handle.IsAllocated;
+        if (ans)
+            Console.WriteLine("GCHandle is allocated");
+
+        if (ans == false)
+        {
+            Console.WriteLine("Test for GCHandle.Free() passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for GCHandle.Free() failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Free.csproj b/src/coreclr/tests/src/GC/API/GCHandle/Free.csproj
new file mode 100644 (file)
index 0000000..c0e2d02
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Free.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Free_neg.cs b/src/coreclr/tests/src/GC/API/GCHandle/Free_neg.cs
new file mode 100644 (file)
index 0000000..38c261a
--- /dev/null
@@ -0,0 +1,51 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GCHandle.Free()
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test
+{
+    public static int Main()
+    {
+        int[] array = new int[25];
+
+        bool pass = false;
+
+        Console.WriteLine("Allocating a handle to object..");
+        GCHandle handle = GCHandle.Alloc(array);
+
+        handle.Free();
+
+        Console.WriteLine("Freeing the handle...");
+
+        try
+        {
+            handle.Free();
+        }
+        catch (InvalidOperationException)
+        {
+            Console.WriteLine("Expected InvalidOperationException");
+            pass = true;
+        }
+        catch (Exception)
+        {
+            Console.WriteLine("This should NOT throw an exception:");
+            pass = false;
+        }
+
+        if (pass)
+        {
+            Console.WriteLine("Test for GCHandle.Free() passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for GCHandle.Free() failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Free_neg.csproj b/src/coreclr/tests/src/GC/API/GCHandle/Free_neg.csproj
new file mode 100644 (file)
index 0000000..a053431
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Free_neg.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/HandleCopy.cs b/src/coreclr/tests/src/GC/API/GCHandle/HandleCopy.cs
new file mode 100644 (file)
index 0000000..ccc124c
--- /dev/null
@@ -0,0 +1,82 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests Copy of GCHandleType.Weak .. the object with GCHandleType Weak 
+// will be collected. The handle and it's copy remain allocated even after the object is collected.
+// Also tests the target of the handle.
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test
+{
+    public class Dummy
+    {
+        public static int flag = 0;
+
+        ~Dummy()
+        {
+            Console.WriteLine("In Finalize() of Dummy");
+            flag = 99;
+        }
+    }
+
+    public class CreateObj
+    {
+        public Dummy obj;
+        public GCHandle handle, copy;
+
+        public CreateObj()
+        {
+            obj = new Dummy();
+            Console.WriteLine("Allocating a Weak handle to object..");
+            handle = GCHandle.Alloc(obj, GCHandleType.Weak);
+
+            // making a copy of the handle
+            copy = handle;
+        }
+
+        public bool RunTest()
+        {
+            // ensuring that GC happens even with /debug mode
+            obj = null;
+            GC.Collect();
+
+            GC.WaitForPendingFinalizers();
+
+            bool ans1 = handle.IsAllocated;
+            bool ans2 = copy.IsAllocated;
+
+            //Console.WriteLine("handle.IsAllocated = " + ans1);
+            //Console.WriteLine("copy.IsAllocated = " + ans2);
+
+            Dummy target1 = (Dummy)handle.Target;
+            Dummy target2 = (Dummy)copy.Target;
+
+            if (((ans1 == true) && (ans2 == true)) && ((target1 == null) && (target2 == null)))
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+    }
+
+    public static int Main()
+    {
+        CreateObj temp = new CreateObj();
+        if (temp.RunTest())
+        {
+            Console.WriteLine("Test for Copy of GCHandle passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for Copy of GCHandle failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/HandleCopy.csproj b/src/coreclr/tests/src/GC/API/GCHandle/HandleCopy.csproj
new file mode 100644 (file)
index 0000000..be3ca8d
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="HandleCopy.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/IsAllocated.cs b/src/coreclr/tests/src/GC/API/GCHandle/IsAllocated.cs
new file mode 100644 (file)
index 0000000..33ad109
--- /dev/null
@@ -0,0 +1,49 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GCHandle.IsAllocated 
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test
+{
+    public static int Main()
+    {
+        int[] array = new int[25];
+
+        Console.WriteLine("Allocating a handle to object..");
+        GCHandle handle = GCHandle.Alloc(array);
+
+        bool ans1 = handle.IsAllocated;
+
+        Console.Write("GCHandle.IsAllocated = ");
+
+        if (ans1)
+            Console.WriteLine("True");
+        else
+            Console.WriteLine("False");
+
+        Console.WriteLine("Freeing the handle...");
+        handle.Free();
+
+        bool ans2 = handle.IsAllocated;
+        Console.Write("GCHandle.IsAllocated = ");
+        if (ans2)
+            Console.WriteLine("True");
+        else
+            Console.WriteLine("False");
+
+        if ((ans1 == true) && (ans2 == false))
+        {
+            Console.WriteLine("Test for GCHandle.IsAllocated passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for GCHandle.IsAllocated failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/IsAllocated.csproj b/src/coreclr/tests/src/GC/API/GCHandle/IsAllocated.csproj
new file mode 100644 (file)
index 0000000..1091eee
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="IsAllocated.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Normal.cs b/src/coreclr/tests/src/GC/API/GCHandle/Normal.cs
new file mode 100644 (file)
index 0000000..6fc46ee
--- /dev/null
@@ -0,0 +1,48 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GCHandleType.Normal .. the object with GCHandleType Normal 
+// should not be collected.
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test {
+
+       public class Dummy {
+
+               public static int flag=0;
+               ~Dummy() {
+                       Console.WriteLine("In Finalize() of Dummy");    
+                       flag=99;
+               }
+       }
+
+       public static int Main() {
+
+               Dummy obj = new Dummy();
+               
+               Console.WriteLine("Allocating a normal handle to object..");
+               GCHandle handle = GCHandle.Alloc(obj,GCHandleType.Normal); // Normal handle
+               
+               // ensuring that GC happens even with /debug mode
+               obj=null;
+
+               GC.Collect();
+               GC.WaitForPendingFinalizers();
+               
+               if(Dummy.flag == 0) {
+                       
+                       Console.WriteLine("Test for GCHandleType.Normal passed!");
+            return 100;
+               }
+               else {
+                       
+                       Console.WriteLine("Test for GCHandleType.Normal failed!");
+            return 1;
+               }
+
+
+       }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Normal.csproj b/src/coreclr/tests/src/GC/API/GCHandle/Normal.csproj
new file mode 100644 (file)
index 0000000..cc462b9
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments></CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Normal.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/PinObj_neg.cs b/src/coreclr/tests/src/GC/API/GCHandle/PinObj_neg.cs
new file mode 100644 (file)
index 0000000..2a70fc7
--- /dev/null
@@ -0,0 +1,40 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests Pinned handle for array of Objects...
+// Pinning of "Object" type is not allowed and should throw an exception.
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test
+{
+    public static int Main()
+    {
+        Object[] array = new Object[25];
+
+        Console.WriteLine("Trying to pin array of objects..");
+        Console.WriteLine("Should throw an exception");
+        try
+        {
+            GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned);
+        }
+        catch (ArgumentException)
+        {
+            Console.WriteLine("Expected ArgumentException");
+
+            Console.WriteLine("Test passed!");
+            return 100;
+        }
+        catch (Exception)
+        {
+            Console.WriteLine("Unexpected exception:");
+            return 2;
+        }
+
+
+        Console.WriteLine("Test failed!");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/PinObj_neg.csproj b/src/coreclr/tests/src/GC/API/GCHandle/PinObj_neg.csproj
new file mode 100644 (file)
index 0000000..dc1b445
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="PinObj_neg.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Pinned.cs b/src/coreclr/tests/src/GC/API/GCHandle/Pinned.cs
new file mode 100644 (file)
index 0000000..22527c9
--- /dev/null
@@ -0,0 +1,44 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GCHandleType.Pinned .. the pinned object should not be collected.
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test
+{
+    public static int Main()
+    {
+        int[] array = new int[25];
+
+        Console.WriteLine("Allocating a pinned handle to object..");
+        GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned); // Pinned handle
+
+        //int gen1 = GC.GetGeneration(array);
+        //Console.WriteLine("Object is in generation " + gen1);
+
+        IntPtr addr1 = handle.AddrOfPinnedObject();
+
+        // ensuring that GC happens even with /debug mode
+        array = null;
+        GC.Collect();
+
+        //int gen2 = GC.GetGeneration(array);
+        //Console.WriteLine("Object is in generation " + gen2);
+
+        IntPtr addr2 = handle.AddrOfPinnedObject();
+
+        if (addr1 == addr2)
+        {
+            Console.WriteLine("Test for GCHandleType.Pinned passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for GCHandleType.Pinned failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Pinned.csproj b/src/coreclr/tests/src/GC/API/GCHandle/Pinned.csproj
new file mode 100644 (file)
index 0000000..ccbdb65
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Pinned.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Target.cs b/src/coreclr/tests/src/GC/API/GCHandle/Target.cs
new file mode 100644 (file)
index 0000000..7f42cfe
--- /dev/null
@@ -0,0 +1,68 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GCHandle.Target
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test
+{
+    public class Dummy
+    {
+        public int flag;
+
+        public Dummy(int i)
+        {
+            flag = i;
+        }
+
+        public int getFlag()
+        {
+            return flag;
+        }
+    }
+    public static int Main()
+    {
+        Dummy obj = new Dummy(99);
+        bool passed = true;
+
+        Console.WriteLine("Allocating a handle to object..");
+        GCHandle handle = GCHandle.Alloc(obj);
+
+        Dummy target = (Dummy)handle.Target;
+
+        if (target.getFlag() == 99)
+        {
+            Console.WriteLine("Test for GCHandle.get_Target passed!");
+        }
+        else
+        {
+            Console.WriteLine("Test for GCHandle.get_Target failed!");
+            passed = false;
+        }
+
+        Dummy obj2 = new Dummy(66);
+        handle.Target = obj2;
+        Dummy target2 = (Dummy)handle.Target;
+
+        if (target2.getFlag() == 66)
+        {
+            Console.WriteLine("Test for GCHandle.set_Target passed!");
+        }
+        else
+        {
+            Console.WriteLine("Test for GCHandle.set_Target failed!");
+            passed = false;
+        }
+
+        if (passed)
+        {
+            Console.WriteLine("Test Passed!");
+            return 100;
+        }
+        Console.WriteLine("Test Failed!");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Target.csproj b/src/coreclr/tests/src/GC/API/GCHandle/Target.csproj
new file mode 100644 (file)
index 0000000..53825f8
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Target.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Target_neg.cs b/src/coreclr/tests/src/GC/API/GCHandle/Target_neg.cs
new file mode 100644 (file)
index 0000000..1434a8a
--- /dev/null
@@ -0,0 +1,75 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GCHandle.Target negative scenarios
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test
+{
+    public static int Main()
+    {
+        bool passed = true;
+
+        Object o = new Object();
+        GCHandle gch = GCHandle.Alloc(o);
+        gch.Free();
+
+        try
+        {
+            gch.Target = o;
+        }
+        catch (InvalidOperationException)
+        {
+            Console.WriteLine("Caught expected InvalidOperationException");
+        }
+        catch (Exception)
+        {
+            Console.WriteLine("Caught unexpected exception!");
+
+            Console.WriteLine("Test1 Failed!");
+            passed = false;
+        }
+
+        try
+        {
+            Object o2 = gch.Target;
+        }
+        catch (InvalidOperationException)
+        {
+            Console.WriteLine("Caught expected InvalidOperationException");
+        }
+        catch (Exception)
+        {
+            Console.WriteLine("Caught unexpected exception!");
+            Console.WriteLine("Test2 Failed!");
+            passed = false;
+        }
+
+        try
+        {
+            Object o2 = gch.Target;
+        }
+        catch (InvalidOperationException)
+        {
+            Console.WriteLine("Caught expected InvalidOperationException");
+        }
+        catch (Exception)
+        {
+            Console.WriteLine("Caught unexpected exception!");
+            Console.WriteLine("Test3 Failed!");
+            passed = false;
+        }
+
+        if (!passed)
+        {
+            Console.WriteLine("Test Failed!");
+            return 1;
+        }
+
+        Console.WriteLine("Test Passed!");
+        return 100;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Target_neg.csproj b/src/coreclr/tests/src/GC/API/GCHandle/Target_neg.csproj
new file mode 100644 (file)
index 0000000..0c843b0
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Target_neg.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/ToFromIntPtr.cs b/src/coreclr/tests/src/GC/API/GCHandle/ToFromIntPtr.cs
new file mode 100644 (file)
index 0000000..520ca4d
--- /dev/null
@@ -0,0 +1,127 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*
+ * TEST:        ToFromIntPtrTest
+ * DESCRIPTION: Added ToIntPtr and FromIntPtr methods to adhere to FXCop rule "OperatorOverloadsHaveNamedAlternativeMethods".
+ *              See also Casting.cs test.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Dummy
+{
+    public Dummy(int i)
+    {
+        this.i = i;
+    }
+    public int i;
+}
+
+
+public class ToFromIntPtrTest
+{
+    private int _numTests = 0;
+
+    private bool ToFromTest()
+    {
+        _numTests++;
+
+        int dummyValue = 101;
+
+        GCHandle gch = GCHandle.Alloc(new Dummy(dummyValue));
+        GCHandle gch2 = GCHandle.FromIntPtr(GCHandle.ToIntPtr(gch));
+
+        if (gch.Target == gch2.Target)
+        {
+            Console.WriteLine("ToFromTest Passed");
+            return true;
+        }
+
+        Console.WriteLine("ToFromTest Failed");
+        return false;
+    }
+
+
+    private bool FromZeroTest()
+    {
+        _numTests++;
+        try
+        {
+            GCHandle gch3 = GCHandle.FromIntPtr(IntPtr.Zero);
+        }
+        catch (InvalidOperationException)
+        {
+            Console.WriteLine("FromZeroTest Passed");
+            return true;
+        }
+        catch (Exception e)
+        {
+            Console.WriteLine("Unexpected Exception:");
+            //Console.WriteLine(e);
+        }
+
+        Console.WriteLine("FromZeroTest Failed");
+        return false;
+    }
+
+
+    private bool ToZeroTest()
+    {
+        _numTests++;
+
+        GCHandle gch = GCHandle.Alloc(new Dummy(99));
+        gch.Free();
+        IntPtr intPtr = GCHandle.ToIntPtr(gch);
+
+        if (intPtr == IntPtr.Zero)
+        {
+            Console.WriteLine("ToZeroTest Passed");
+            return true;
+        }
+
+        Console.WriteLine("ToZeroTest Failed");
+        return false;
+    }
+
+
+    public bool RunTests()
+    {
+        int numPassed = 0;
+
+        if (ToFromTest())
+        {
+            numPassed++;
+        }
+
+        if (ToZeroTest())
+        {
+            numPassed++;
+        }
+
+        if (FromZeroTest())
+        {
+            numPassed++;
+        }
+
+        Console.WriteLine();
+        return (_numTests == numPassed);
+    }
+
+
+    public static int Main()
+    {
+        ToFromIntPtrTest t = new ToFromIntPtrTest();
+
+        if (t.RunTests())
+        {
+            Console.WriteLine("ToFromIntPtrTest Passed!");
+            return 100;
+        }
+
+        Console.WriteLine("ToFromIntPtrTest Failed!");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/ToFromIntPtr.csproj b/src/coreclr/tests/src/GC/API/GCHandle/ToFromIntPtr.csproj
new file mode 100644 (file)
index 0000000..f083c12
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="ToFromIntPtr.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Weak.cs b/src/coreclr/tests/src/GC/API/GCHandle/Weak.cs
new file mode 100644 (file)
index 0000000..8bcedd2
--- /dev/null
@@ -0,0 +1,68 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests GCHandleType.Weak .. the object with GCHandleType Weak 
+// will be collected.
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test
+{
+    public class Dummy
+    {
+        public static int flag = 0;
+        ~Dummy()
+        {
+            Console.WriteLine("In Finalize() of Dummy");
+            flag = 99;
+        }
+    }
+
+    public class CreateObj
+    {
+        public Dummy obj;
+
+        public CreateObj()
+        {
+            obj = new Dummy();
+            Console.WriteLine("Allocating a Weak handle to object..");
+            GCHandle handle = GCHandle.Alloc(obj, GCHandleType.Weak);
+        }
+
+        public bool RunTest()
+        {
+            // ensuring that GC happens even with /debug mode
+            obj = null;
+            GC.Collect();
+
+            GC.WaitForPendingFinalizers();
+
+            if (Dummy.flag == 99)
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+    }
+
+    public static int Main()
+    {
+        CreateObj temp = new CreateObj();
+
+        if (temp.RunTest())
+        {
+            Console.WriteLine("Test for GCHandleType.Weak passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for GCHandleType.Weak failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/Weak.csproj b/src/coreclr/tests/src/GC/API/GCHandle/Weak.csproj
new file mode 100644 (file)
index 0000000..89c330b
--- /dev/null
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Weak.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+    <None Include="app.config" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandle/app.config b/src/coreclr/tests/src/GC/API/GCHandle/app.config
new file mode 100644 (file)
index 0000000..6f7bbd9
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/API/GCHandleCollector/Count.cs b/src/coreclr/tests/src/GC/API/GCHandleCollector/Count.cs
new file mode 100644 (file)
index 0000000..e24b99a
--- /dev/null
@@ -0,0 +1,224 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Count
+{
+    private int _totalTestCount = 0;
+
+
+    // count should be 0 by default
+    public bool EmptyTest()
+    {
+        _totalTestCount++;
+
+        HandleCollector hc = new HandleCollector(null, 1);
+
+        if (hc.Count != 0)
+        {
+            Console.WriteLine("EmptyTest Failed!");
+            return false;
+        }
+
+        Console.WriteLine("EmptyTest Passed!");
+        return true;
+    }
+
+
+    public bool AddTest()
+    {
+        _totalTestCount++;
+
+
+        HandleCollector hc = new HandleCollector(null, 1);
+
+        for (int i = 1; i <= 1000; i++)
+        {
+            hc.Add();
+            if (hc.Count != i)
+            {
+                Console.WriteLine("AddTest Failed!");
+                return false;
+            }
+        }
+
+        Console.WriteLine("AddTest Passed!");
+        return true;
+    }
+
+
+    public bool RemoveTest()
+    {
+        _totalTestCount++;
+
+
+        HandleCollector hc = new HandleCollector(null, 1);
+
+        for (int i = 1; i <= 1000; i++)
+        {
+            hc.Add();
+        }
+
+        for (int i = 999; i >= 0; i--)
+        {
+            hc.Remove();
+
+            if (hc.Count != i)
+            {
+                Console.WriteLine("RemoveTest Failed!");
+                return false;
+            }
+        }
+
+        Console.WriteLine("RemoveTest Passed!");
+        return true;
+    }
+
+
+
+    public bool StressTest()
+    {
+        _totalTestCount++;
+
+
+        HandleCollector hc = new HandleCollector(null, 1);
+
+        for (int i = 1; i <= 10000000; i++)
+        {
+            hc.Add();
+            if (hc.Count != i)
+            {
+                Console.WriteLine("StressTest1 Failed!");
+                return false;
+            }
+        }
+
+
+        for (int i = 9999999; i <= 0; i++)
+        {
+            hc.Remove();
+            if (hc.Count != i)
+            {
+                Console.WriteLine("StressTest2 Failed!");
+                return false;
+            }
+        }
+
+        Console.WriteLine("StressTest Passed!");
+        return true;
+    }
+
+
+
+    public bool MixedTest()
+    {
+        _totalTestCount++;
+
+
+        HandleCollector hc = new HandleCollector(null, 1);
+
+        int i, j, k;
+
+        for (i = 1; i <= 100; i++)
+        {
+            hc.Add();
+            if (hc.Count != i)
+            {
+                Console.WriteLine("MixedTest1 Failed!");
+                return false;
+            }
+        }
+
+        i--;
+
+        for (j = 1; j <= 50; j++)
+        {
+            hc.Remove();
+
+            if (hc.Count != i - j)
+            {
+                Console.WriteLine("MixedTest2 Failed!");
+                return false;
+            }
+        }
+
+        j--;
+
+        for (k = 1; k <= 50; k++)
+        {
+            hc.Add();
+            if (hc.Count != (i - j) + k)
+            {
+                Console.WriteLine("MixedTest3 Failed!");
+                return false;
+            }
+        }
+
+        k--;
+
+        // do check here
+        if (hc.Count != (i - j + k))
+        {
+            Console.WriteLine("MixedTest Failed!");
+            Console.WriteLine("Count: {0}", hc.Count);
+            Console.WriteLine("{0}", (i - j + k));
+            return false;
+        }
+
+        Console.WriteLine("MixedTest Passed!");
+        return true;
+    }
+
+
+    public bool RunTest()
+    {
+        int count = 0;
+
+        if (EmptyTest())
+        {
+            count++;
+        }
+
+        if (AddTest())
+        {
+            count++;
+        }
+
+        if (RemoveTest())
+        {
+            count++;
+        }
+
+
+        if (StressTest())
+        {
+            count++;
+        }
+
+        if (MixedTest())
+        {
+            count++;
+        }
+
+        Console.WriteLine();
+        return (count == _totalTestCount);
+    }
+
+
+    public static int Main()
+    {
+        Count c = new Count();
+
+        if (c.RunTest())
+        {
+            Console.WriteLine("Test Passed!");
+            return 100;
+        }
+
+        Console.WriteLine("Test Failed!");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandleCollector/Count.csproj b/src/coreclr/tests/src/GC/API/GCHandleCollector/Count.csproj
new file mode 100644 (file)
index 0000000..26eba72
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Count.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandleCollector/CtorsAndProperties.cs b/src/coreclr/tests/src/GC/API/GCHandleCollector/CtorsAndProperties.cs
new file mode 100644 (file)
index 0000000..adecf9c
--- /dev/null
@@ -0,0 +1,128 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Handler
+{
+    private int _totalTestCount = 0;
+
+
+    public bool GetInitialThresholdTest()
+    {
+        _totalTestCount++;
+        int count = 0;
+
+        HandleCollector hc = null;
+
+        int[] initialValues = { 0, 1, 2, 3, 1000, 10000, Int32.MaxValue / 2, Int32.MaxValue };
+
+        foreach (int i in initialValues)
+        {
+            hc = new HandleCollector(null, i);
+            if (hc.InitialThreshold == i)
+                count++;
+        }
+
+        if (count != initialValues.Length)
+        {
+            Console.WriteLine("GetInitialThresholdTest Failed!");
+            return false;
+        }
+
+        return true;
+    }
+
+
+    public bool GetMaximumThresholdTest()
+    {
+        _totalTestCount++;
+        int count = 0;
+
+        HandleCollector hc = null;
+
+        int[] maxValues = { 0, 1, 2, 3, 1000, 10000, Int32.MaxValue / 2, Int32.MaxValue };
+
+        foreach (int i in maxValues)
+        {
+            hc = new HandleCollector(null, 0, i);
+            if (hc.MaximumThreshold == i)
+                count++;
+        }
+
+        if (count != maxValues.Length)
+        {
+            Console.WriteLine("GetMaximumThresholdTest Failed!");
+            return false;
+        }
+
+        return true;
+    }
+
+
+    public bool GetName()
+    {
+        _totalTestCount++;
+        int count = 0;
+
+        HandleCollector hc = null;
+
+        string[] names = { String.Empty, "a", "name", "name with spaces", new String('a', 50000), "\uA112\uA0E4\uA0F9" };
+
+        foreach (string s in names)
+        {
+            hc = new HandleCollector(s, 0);
+            if (hc.Name == s)
+                count++;
+        }
+
+        if (count != names.Length)
+        {
+            Console.WriteLine("GetNameTest Failed!");
+            return false;
+        }
+
+        return true;
+    }
+
+
+    public bool RunTest()
+    {
+        int count = 0;
+
+        if (GetInitialThresholdTest())
+        {
+            count++;
+        }
+
+        if (GetMaximumThresholdTest())
+        {
+            count++;
+        }
+
+        if (GetName())
+        {
+            count++;
+        }
+
+
+        return (count == _totalTestCount);
+    }
+
+
+    public static int Main()
+    {
+        Handler h = new Handler();
+
+        if (h.RunTest())
+        {
+            Console.WriteLine("Test Passed!");
+            return 100;
+        }
+
+        Console.WriteLine("Test Failed!");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandleCollector/CtorsAndProperties.csproj b/src/coreclr/tests/src/GC/API/GCHandleCollector/CtorsAndProperties.csproj
new file mode 100644 (file)
index 0000000..964ece5
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="CtorsAndProperties.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandleCollector/NegTests.cs b/src/coreclr/tests/src/GC/API/GCHandleCollector/NegTests.cs
new file mode 100644 (file)
index 0000000..b1070d4
--- /dev/null
@@ -0,0 +1,178 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Handler
+{
+    private int _totalTestCount = 0;
+
+    // tests various invalid constructor values
+    public bool ConstructorTest()
+    {
+        _totalTestCount++;
+
+        HandleCollector hc = null;
+        int count = 0;
+        int testcount = 0;
+
+        try
+        {
+            testcount++;
+            // negative maxThreshold
+            hc = new HandleCollector(null, 0, -1);
+        }
+        catch (System.ArgumentOutOfRangeException)
+        {
+            count++;
+        }
+
+        try
+        {
+            testcount++;
+            // negative initialThreshold
+            hc = new HandleCollector(null, -1, 0);
+        }
+        catch (System.ArgumentOutOfRangeException)
+        {
+            count++;
+        }
+
+        try
+        {
+            testcount++;
+            // negative maxThreshold & initialThreshold
+            hc = new HandleCollector(null, -1, -1);
+        }
+        catch (System.ArgumentOutOfRangeException)
+        {
+            count++;
+        }
+
+        try
+        {
+            testcount++;
+            // maxThreshold < initialThreshold
+            hc = new HandleCollector(null, 1, 0);
+        }
+        catch (System.ArgumentException)
+        {
+            count++;
+        }
+
+
+        if (count < testcount)
+        {
+            Console.WriteLine("ConstructorTest Failed!");
+            return false;
+        }
+
+
+        Console.WriteLine("ConstructorTest Passed!");
+        return true;
+    }
+
+
+    // should throw InvalidOperationException if removing when Count == 0
+    public bool RemoveTest()
+    {
+        _totalTestCount++;
+
+        HandleCollector hc = new HandleCollector(null, 1);
+
+        if (hc.Count != 0)
+        {
+            Console.WriteLine("Count value not zero: {0}!", hc.Count);
+            Console.WriteLine("RemoveTest Aborted!");
+            return false;
+        }
+
+        try
+        {
+            hc.Remove();
+        }
+        catch (InvalidOperationException)
+        {
+            Console.WriteLine("RemoveTest Passed!");
+            return true;
+        }
+
+        Console.WriteLine("RemoveTest Failed!");
+        return false;
+    }
+
+
+    // should throw InvalidOperationException if adding when Count == int.MaxValue
+    // unfortunately this test takes too long to run (~30 mins on a 1.8MHz machine)
+    public bool AddTest()
+    {
+        _totalTestCount++;
+
+        HandleCollector hc = new HandleCollector(null, int.MaxValue);
+
+        for (int i = 1; i < int.MaxValue; i++)
+        {
+            hc.Add();
+            if (hc.Count != i)
+            {
+                Console.WriteLine("AddTest Failed!1");
+                Console.WriteLine("i: {0}", i);
+                Console.WriteLine("count: {0}", hc.Count);
+                return false;
+            }
+        }
+
+        try
+        {
+            hc.Add(); // int.MaxValue+1
+        }
+        catch (InvalidOperationException)
+        {
+            Console.WriteLine("AddTest Passed!");
+            return true;
+        }
+
+        Console.WriteLine("AddTest Failed!2");
+        Console.WriteLine(hc.Count);
+        return false;
+    }
+
+
+    public bool RunTest()
+    {
+        int count = 0;
+
+        if (ConstructorTest())
+        {
+            count++;
+        }
+
+        if (RemoveTest())
+        {
+            count++;
+        }
+
+        // if (AddTest()) {
+        //     count++;
+        // }
+
+        return (count == _totalTestCount);
+    }
+
+
+    public static int Main()
+    {
+        Handler h = new Handler();
+
+        if (h.RunTest())
+        {
+            Console.WriteLine("Test Passed!");
+            return 100;
+        }
+
+        Console.WriteLine("Test Failed!");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandleCollector/NegTests.csproj b/src/coreclr/tests/src/GC/API/GCHandleCollector/NegTests.csproj
new file mode 100644 (file)
index 0000000..5b45c64
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="NegTests.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandleCollector/Usage.cs b/src/coreclr/tests/src/GC/API/GCHandleCollector/Usage.cs
new file mode 100644 (file)
index 0000000..14088f0
--- /dev/null
@@ -0,0 +1,226 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/* TEST: Usage
+ * DESCRIPTION: Three usage scenarios that monitor the number of live handles and GC Collections
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+// the class that holds the HandleCollectors
+public class HandleCollectorTest
+{
+    private static HandleCollector s_hc = new HandleCollector("hc", 100);
+
+    public HandleCollectorTest()
+    {
+        s_hc.Add();
+    }
+
+    public static int Count
+    {
+        get { return s_hc.Count; }
+    }
+
+    ~HandleCollectorTest()
+    {
+        s_hc.Remove();
+    }
+
+    public static void Reset()
+    {
+        GC.Collect();
+        GC.WaitForPendingFinalizers();
+        GC.Collect();
+        s_hc = new HandleCollector("hc", 100);
+    }
+}
+
+
+public class Usage
+{
+    private int _numTests = 0;
+    private int _numInstances = 100;
+    private const int deltaPercent = 10;
+
+    // ensures GC Collections occur when handle count exceeds maximum
+    private bool Case1()
+    {
+        _numTests++;
+
+        // clear GC
+        GC.Collect();
+        GC.WaitForPendingFinalizers();
+        GC.Collect();
+
+        HandleCollectorTest h;
+        int original = GC.CollectionCount(0);
+
+        // create objects and let them go out of scope
+        for (int i = 0; i < _numInstances; i++)
+            h = new HandleCollectorTest();
+
+        h = null;
+        GC.WaitForPendingFinalizers();
+
+        // Collection should not have occurred
+        if (GC.CollectionCount(0) != original)
+        {
+            Console.WriteLine("Early collection!");
+            Console.WriteLine("Case 1 Failed!");
+            return false;
+        }
+
+        new HandleCollectorTest();
+
+        if ((GC.CollectionCount(0) - original) > 0)
+        {
+            Console.WriteLine("Case 1 Passed!");
+            return true;
+        }
+
+        Console.WriteLine("Expected collection did not occur!");
+        Console.WriteLine("Case 1 Failed!");
+        return false;
+    }
+
+    // ensures GC Collection does not occur when handle count stays below maximum
+    private bool Case2()
+    {
+        _numTests++;
+        int handleCount = 0;
+
+        for (int i = 0; i < _numInstances; i++)
+        {
+            new HandleCollectorTest();
+            GC.WaitForPendingFinalizers();
+            handleCount = HandleCollectorTest.Count;
+            //Note that the GC should occur when handle count is 101 but it will happen at anytime after a creation and we stick to the previous
+            //count to avoid error
+        }
+
+        Console.WriteLine("{0}, {1}", handleCount, _numInstances);
+
+        if (handleCount == _numInstances)
+        {
+            Console.WriteLine("Case 2 Passed!");
+            return true;
+        }
+
+        Console.WriteLine("Case 2 Failed!");
+        return false;
+    }
+
+
+    // ensures GC Collections frequency decrease by threshold
+    private bool Case3()
+    {
+        _numTests++;
+
+        int gcCount = GC.CollectionCount(2);
+        int handleCount = HandleCollectorTest.Count;
+        int prevHandleCount = HandleCollectorTest.Count;
+
+        List<HandleCollectorTest> list = new List<HandleCollectorTest>();
+
+        for (int i = 0; i < deltaPercent; i++)
+        {
+            do
+            {
+                HandleCollectorTest h = new HandleCollectorTest();
+                if ((HandleCollectorTest.Count % 2) == 0)
+                    list.Add(h);
+                GC.WaitForPendingFinalizers();
+                if (GC.CollectionCount(2) != gcCount)
+                {
+                    gcCount = GC.CollectionCount(2);
+                    break;
+                }
+                else
+                    handleCount = HandleCollectorTest.Count;
+            } while (true);
+
+            // ensure threshold is increasing
+            if (!CheckPercentageIncrease(handleCount, prevHandleCount))
+            {
+                Console.WriteLine("Case 3 failed: threshold not increasing!");
+                return false;
+            }
+            prevHandleCount = handleCount;
+        }
+
+
+        Console.WriteLine("Case 3 Passed!");
+        return true;
+    }
+
+
+    // Checks that the threshold increases are within 0.2 error margine of deltaPercent
+    private bool CheckPercentageIncrease(int current, int previous)
+    {
+        bool retValue = true;
+        if (previous != 0)
+        {
+            double value = ((double)(current - previous)) / (double)previous;
+            double expected = (double)deltaPercent / 100;
+            double errorMargin = Math.Abs((double)(value - expected) / (double)expected);
+            retValue = (errorMargin < 0.2);
+        }
+
+        return retValue;
+    }
+
+
+    public bool RunTest()
+    {
+        int numPassed = 0;
+
+        if (Case1())
+        {
+            numPassed++;
+        }
+
+        HandleCollectorTest.Reset();
+
+        if (Case2())
+        {
+            numPassed++;
+        }
+
+        HandleCollectorTest.Reset();
+
+        if (Case3())
+        {
+            numPassed++;
+        }
+
+        return (numPassed == _numTests);
+    }
+
+
+    public static int Main()
+    {
+        if (GC.CollectionCount(0) > 20)
+        {
+            Console.WriteLine("GC Stress is enabled");
+            Console.WriteLine("Abort Test");
+            return 100;
+        }
+
+        Usage u = new Usage();
+
+        if (u.RunTest())
+        {
+            Console.WriteLine();
+            Console.WriteLine("Test Passed!");
+            return 100;
+        }
+
+        Console.WriteLine();
+        Console.WriteLine("Test Failed!");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/GCHandleCollector/Usage.csproj b/src/coreclr/tests/src/GC/API/GCHandleCollector/Usage.csproj
new file mode 100644 (file)
index 0000000..4868206
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Usage.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCHandleCollector/app.config b/src/coreclr/tests/src/GC/API/GCHandleCollector/app.config
new file mode 100644 (file)
index 0000000..6f7bbd9
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
index 558cf98..fd69965 100644 (file)
     <Compile Include="ILatencyTest.cs" />
   </ItemGroup>
   <ItemGroup>
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
index fd39551..209a492 100644 (file)
     <Compile Include="InducedGen0GC.cs" />
   </ItemGroup>
   <ItemGroup>
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
index df1e8fb..a97ec75 100644 (file)
     <Compile Include="InducedGen1GC.cs" />
   </ItemGroup>
   <ItemGroup>
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
index b8a3516..1f4cd32 100644 (file)
     <Compile Include="InducedGen2GC.cs" />
   </ItemGroup>
   <ItemGroup>
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
diff --git a/src/coreclr/tests/src/GC/API/GCSettings/InputValidation.cs b/src/coreclr/tests/src/GC/API/GCSettings/InputValidation.cs
new file mode 100644 (file)
index 0000000..ea01ab7
--- /dev/null
@@ -0,0 +1,147 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Runtime;
+
+//Testing what GC Latency Modes can be set, depending on what is the original GC setting
+public class InputValidation
+{
+    static GCLatencyMode initialMode = GCSettings.LatencyMode;
+    static bool server = false;
+    static bool nonConcurrent = false;
+
+    public static int Main()
+    {
+        //Detect on what config we are running
+        if (!DetectInitialMode())
+            return 25;
+
+        InputValidationTest test = new InputValidationTest(server, nonConcurrent);
+
+        return test.Run();
+
+    }
+
+    static bool DetectInitialMode()
+    {
+        if (System.Runtime.GCSettings.IsServerGC)
+        {
+            Console.Write("Server GC ");
+            server = true;
+        }
+        else
+        {
+            Console.Write("Workstation ");
+        }
+
+
+        if (initialMode == GCLatencyMode.Batch)
+        {
+            nonConcurrent = true;
+            Console.WriteLine("Non Concurrent ");
+        }
+        else if (initialMode == GCLatencyMode.Interactive)
+        {
+            Console.WriteLine("Concurrent ");
+        }
+        else
+        {
+            Console.WriteLine("Unexpected GC mode");
+            return false;
+        }
+        return true;
+    }
+
+    class InputValidationTest
+    {
+
+        public List<GCLatencyMode> totalInputs = new List<GCLatencyMode>(new GCLatencyMode[] { GCLatencyMode.Batch, GCLatencyMode.Interactive, GCLatencyMode.LowLatency, GCLatencyMode.SustainedLowLatency });
+        public List<GCLatencyMode> validInputs = new List<GCLatencyMode>();
+        public List<GCLatencyMode> invalidInputs = new List<GCLatencyMode>();
+        public List<GCLatencyMode> outOfRangeInputs = new List<GCLatencyMode>(new GCLatencyMode[] { (GCLatencyMode)(GCLatencyMode.Batch - 1), (GCLatencyMode)(GCLatencyMode.SustainedLowLatency + 1) });
+
+        public InputValidationTest(bool server, bool nonconcurrent)
+        {
+            //set the valid inputs and invalid inputs 
+            if (server)
+            {
+                invalidInputs.Add(GCLatencyMode.LowLatency);
+            }
+            if (nonConcurrent)
+            {
+                invalidInputs.Add(GCLatencyMode.SustainedLowLatency);
+            }
+            foreach (GCLatencyMode latency in totalInputs)
+            {
+                if (!invalidInputs.Contains(latency))
+                    validInputs.Add(latency);
+            }
+        }
+
+        public int Run()
+        {
+            int errorCount = 0;
+            Console.WriteLine("Initial mode is {0}", initialMode);
+            for (int i = 0; i < validInputs.Count; i++)
+            {
+                Console.WriteLine("Setting latency mode to {0}", validInputs[i]);
+                GCSettings.LatencyMode = validInputs[i];
+
+                if (GCSettings.LatencyMode != validInputs[i])
+                {
+                    Console.WriteLine("{0} Latency mode doesn't match", validInputs[i]);
+                    errorCount++;
+                }
+                GCSettings.LatencyMode = initialMode;
+            }
+
+            for (int i = 0; i < outOfRangeInputs.Count; i++)
+            {
+                try
+                {
+                    Console.WriteLine("Setting latency mode to {0}", outOfRangeInputs[i]);
+                    GCSettings.LatencyMode = outOfRangeInputs[i];
+                    Console.WriteLine("Should not have been able to set latency mode to {0}", invalidInputs[i]);
+                    errorCount++;
+                }
+                catch (ArgumentOutOfRangeException)
+                {
+                    Console.WriteLine("ArgumentOutOfRangeException (expected)");
+                }
+            }
+
+            GCSettings.LatencyMode = initialMode;
+            for (int i = 0; i < invalidInputs.Count; i++)
+            {
+                Console.WriteLine("Setting latency mode to {0}", invalidInputs[i]);
+                GCSettings.LatencyMode = invalidInputs[i];
+
+                if (GCSettings.LatencyMode != initialMode)
+                {
+                    Console.WriteLine("Latency mode should not have changed to {0}", GCSettings.LatencyMode);
+                    errorCount++;
+                }
+                GCSettings.LatencyMode = initialMode;
+            }
+
+            if (errorCount > 0)
+            {
+                Console.WriteLine("{0} errors", errorCount);
+                Console.WriteLine("Test Failed");
+                return errorCount;
+            }
+            Console.WriteLine("Test Passed");
+            return 100;
+
+        }
+
+    }
+
+}
+
+
+
+
diff --git a/src/coreclr/tests/src/GC/API/GCSettings/InputValidation.csproj b/src/coreclr/tests/src/GC/API/GCSettings/InputValidation.csproj
new file mode 100644 (file)
index 0000000..bdf3f93
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments></CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="InputValidation.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/GCSettings/app.config b/src/coreclr/tests/src/GC/API/GCSettings/app.config
new file mode 100644 (file)
index 0000000..6f7bbd9
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/Finalize.cs b/src/coreclr/tests/src/GC/API/WeakReference/Finalize.cs
new file mode 100644 (file)
index 0000000..d873230
--- /dev/null
@@ -0,0 +1,67 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests WeakReference.Finalize()  
+
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test {
+
+    public class Dummy {
+
+        public static bool visited=false;
+        ~Dummy() {
+            Console.WriteLine("In Finalize() of Dummy");    
+            if(visited==false) visited=true;
+            else visited=false;
+        }
+    }
+
+    public class CreateObj {
+        Dummy dummy1;
+        Dummy dummy2;
+
+        public CreateObj() {
+            dummy1 = new Dummy();
+            dummy2 = new Dummy();
+        }
+
+        public bool RunTest() {
+            
+            WeakReference weak1 = new WeakReference(dummy1);
+            GCHandle handle = GCHandle.Alloc(dummy1,GCHandleType.Normal); // Strong Reference
+
+            WeakReference weak2 = new WeakReference(dummy2); // only a weak reference..so should run finalizer
+        
+            // ensuring that GC happens even with /debug mode
+            dummy1=null;
+            dummy2=null;
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            if(Dummy.visited == true) 
+                return true;
+            else 
+                return false;
+        }    
+    }
+
+    public static int Main() {
+        
+        CreateObj temp = new CreateObj();
+        bool passed = temp.RunTest();
+
+        if(passed) {
+            Console.WriteLine("Test for WeakReference.Finalize() passed!");
+            return 100;
+        }
+        else {
+            Console.WriteLine("Test for WeakReference.Finalize() failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/Finalize.csproj b/src/coreclr/tests/src/GC/API/WeakReference/Finalize.csproj
new file mode 100644 (file)
index 0000000..5184a71
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments></CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Finalize.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/Finalize2.cs b/src/coreclr/tests/src/GC/API/WeakReference/Finalize2.cs
new file mode 100644 (file)
index 0000000..84aa27b
--- /dev/null
@@ -0,0 +1,185 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*
+ * TEST NAME: Finalize2
+ * DESCRIPTION: operates on Weakhandles whose targets are being finalized
+ */
+
+using System;
+
+public class GetTargetTest
+{
+    public WeakReference w;
+    static public bool Passed = false;
+
+    public GetTargetTest(bool trackResurrection)
+    {
+        w = new WeakReference(this, trackResurrection);
+    }
+
+    ~GetTargetTest()
+    {
+        Console.WriteLine("Running ~GetTargetTest");
+        // target is being finalized.  Internal handle should be null
+        try
+        {
+            Object o = w.Target;
+            if (o == null)
+            {
+                Console.WriteLine("getTarget passed");
+                Console.WriteLine();
+                Passed = true;
+                return;
+            }
+            GC.KeepAlive(o);
+        }
+        catch (Exception e)
+        {
+            Console.WriteLine(e);
+        }
+
+        Console.WriteLine("getTarget failed");
+        Console.WriteLine();
+    }
+}
+
+public class SetTargetTest
+{
+    public WeakReference w;
+    static public bool Passed = false;
+
+    public SetTargetTest(bool trackResurrection)
+    {
+        w = new WeakReference(this, trackResurrection);
+    }
+
+    ~SetTargetTest()
+    {
+        // target is being finalized.  Internal handle should be null
+        Console.WriteLine("Running ~SetTargetTest");
+
+        try
+        {
+            w.Target = new Object();
+        }
+        catch (InvalidOperationException)
+        {
+            Console.WriteLine("Caught expected InvalidOperationException");
+            Console.WriteLine("setTarget passed");
+            Console.WriteLine();
+            Passed = true;
+            return;
+        }
+        catch (Exception e)
+        {
+            Console.WriteLine(e);
+        }
+
+        Console.WriteLine("setTarget failed");
+        Console.WriteLine();
+    }
+}
+
+public class IsAliveTest
+{
+    public WeakReference w;
+    static public bool Passed = false;
+
+    public IsAliveTest(bool trackResurrection)
+    {
+        w = new WeakReference(this, trackResurrection);
+    }
+
+    ~IsAliveTest()
+    {
+        Console.WriteLine("Running ~IsAliveTest");
+        // target is being finalized.  Internal handle should be null
+
+        try
+        {
+            bool b = w.IsAlive;
+
+            if (!b)
+            {
+                Console.WriteLine("IsAliveTest passed");
+                Console.WriteLine();
+                Passed = true;
+                return;
+            }
+        }
+        catch (Exception e)
+        {
+            Console.WriteLine(e);
+        }
+
+        Console.WriteLine("IsAlive failed");
+        Console.WriteLine();
+    }
+}
+
+public class NullHandle
+{
+    public bool RunTests(bool trackResurrection)
+    {
+        GetTargetTest d1 = new GetTargetTest(trackResurrection);
+        SetTargetTest d2 = new SetTargetTest(trackResurrection);
+        IsAliveTest d3 = new IsAliveTest(trackResurrection);
+
+        // make sure Finalizers are called
+        d1 = null;
+        d2 = null;
+        d3 = null;
+        GC.Collect();
+        GC.WaitForPendingFinalizers();
+        GC.Collect();
+
+        Console.WriteLine();
+
+        return ((GetTargetTest.Passed) && (SetTargetTest.Passed) && (IsAliveTest.Passed));
+    }
+
+
+    public static int Main()
+    {
+        NullHandle t = new NullHandle();
+        bool longPassed = false;
+        bool shortPassed = false;
+
+        if (t.RunTests(false))
+        {
+            Console.WriteLine("Short WR Test Passed!");
+            shortPassed = true;
+        }
+        else
+        {
+            Console.WriteLine("Short WR Test Failed!");
+        }
+
+        Console.WriteLine();
+        Console.WriteLine();
+
+        if (t.RunTests(true))
+        {
+            Console.WriteLine("Long WR Test Passed!");
+            longPassed = true;
+        }
+        else
+        {
+            Console.WriteLine("Long WR Test Failed!");
+        }
+
+        Console.WriteLine();
+        Console.WriteLine();
+
+        if (longPassed && shortPassed)
+        {
+            Console.WriteLine("Test Passed!");
+            return 100;
+        }
+
+        Console.WriteLine("Test Failed!");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/Finalize2.csproj b/src/coreclr/tests/src/GC/API/WeakReference/Finalize2.csproj
new file mode 100644 (file)
index 0000000..ead3f9f
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Finalize2.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/IsAlive.cs b/src/coreclr/tests/src/GC/API/WeakReference/IsAlive.cs
new file mode 100644 (file)
index 0000000..fae70e1
--- /dev/null
@@ -0,0 +1,41 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests WeakReference.IsAlive : IsAlive=true if GC has not occurred on the object 
+
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test {
+    public static int Main() {
+        int[] array = new int[50];
+
+        WeakReference weak = new WeakReference(array);
+                
+        bool ans1 = weak.IsAlive;
+        Console.WriteLine(ans1);
+
+        if(ans1==false) { // GC.Collect() has already occurred..under GCStress
+            Console.WriteLine("Test for WeakReference.IsAlive passed!");
+            return 100;
+        }
+
+        //else, do an expicit collect.
+        array=null;
+        GC.Collect();
+        
+        bool ans2 = weak.IsAlive;
+        Console.WriteLine(ans2);
+
+        if((ans1 == true) && (ans2==false)) {
+            Console.WriteLine("Test for WeakReference.IsAlive passed!");
+            return 100;
+        }
+        else {
+            Console.WriteLine("Test for WeakReference.IsAlive failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/IsAlive.csproj b/src/coreclr/tests/src/GC/API/WeakReference/IsAlive.csproj
new file mode 100644 (file)
index 0000000..e74d92c
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments></CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="IsAlive.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/IsAlive_neg.cs b/src/coreclr/tests/src/GC/API/WeakReference/IsAlive_neg.cs
new file mode 100644 (file)
index 0000000..31ce677
--- /dev/null
@@ -0,0 +1,34 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Negative Test for WeakReference.IsAlive
+// IsAlive=false if GC occurs on object with only a weakreference.
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test {
+    public static int Main() {
+        int[] array = new int[50];
+
+        WeakReference weak = new WeakReference(array); // array has ONLY a weakreference
+
+        // ensuring that GC happens even with /debug mode
+        array=null;
+
+        GC.Collect();
+
+        bool ans = weak.IsAlive;
+        Console.WriteLine(ans);
+
+        if(ans == false) {
+            Console.WriteLine("Negative Test for WeakReference.IsAlive passed!");
+            return 100;
+        }
+        else {
+            Console.WriteLine("Negative Test for WeakReference.IsAlive failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/IsAlive_neg.csproj b/src/coreclr/tests/src/GC/API/WeakReference/IsAlive_neg.csproj
new file mode 100644 (file)
index 0000000..db81ae8
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments></CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="IsAlive_neg.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/NullHandle.cs b/src/coreclr/tests/src/GC/API/WeakReference/NullHandle.cs
new file mode 100644 (file)
index 0000000..eb9cf61
--- /dev/null
@@ -0,0 +1,98 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*
+ * TEST NAME: NullHandle
+ * DESCRIPTION: operates on Weakhandles whose m_handle is null
+ */
+
+using System;
+using System.Runtime.InteropServices;
+using System.Runtime.CompilerServices;
+
+public class WR : WeakReference
+{
+    public WR(Object o) : base(o, false) { }
+
+    ~WR()
+    {
+        Console.WriteLine("Resurrected!");
+        Test.w = this;
+    }
+}
+
+public class Test
+{
+    public static WR w;
+
+    [MethodImplAttribute(MethodImplOptions.NoInlining)]
+    public static WR ReturnWR() { return new WR(new Object()); }
+
+    public static int Main()
+    {
+        int numTests = 0;
+        int numPassed = 0;
+        WR wr = ReturnWR();
+        wr = null;
+
+        // this will resurrect wr
+        GC.Collect();
+        GC.WaitForPendingFinalizers();
+
+        try
+        {
+            numTests++;
+            Console.WriteLine("Get Target Test");
+            Console.WriteLine(Test.w.Target);
+            Console.WriteLine("Passed");
+            numPassed++;
+        }
+
+        catch (Exception e)
+        {
+            Console.WriteLine(e);
+        }
+
+        try
+        {
+            numTests++;
+            Console.WriteLine("IsAlive Test");
+            bool b = Test.w.IsAlive;
+            Console.WriteLine(b);
+
+            if (!b)
+            {
+                Console.WriteLine("Passed");
+                numPassed++;
+            }
+        }
+        catch (Exception e)
+        {
+            Console.WriteLine(e);
+        }
+
+        try
+        {
+            numTests++;
+            Console.WriteLine("Set Target Test");
+            Test.w.Target = new Object();
+        }
+        catch (InvalidOperationException)
+        {
+            numPassed++;
+            Console.WriteLine("Passed");
+        }
+        catch (Exception e)
+        {
+            Console.WriteLine(e);
+        }
+
+        if (numTests == numPassed)
+        {
+            return 100;
+        }
+
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/NullHandle.csproj b/src/coreclr/tests/src/GC/API/WeakReference/NullHandle.csproj
new file mode 100644 (file)
index 0000000..8d236fe
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="NullHandle.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/Target.cs b/src/coreclr/tests/src/GC/API/WeakReference/Target.cs
new file mode 100644 (file)
index 0000000..f30c353
--- /dev/null
@@ -0,0 +1,99 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests WeakReference.Target
+// Retrieves or assigns the object an IsAlive status.
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Dummy
+{
+    public int val = 0;
+
+    public Dummy(int val)
+    {
+        this.val = val;
+    }
+}
+
+public class Test
+{
+    public bool GetTargetTest()
+    {
+        int[] array = new int[50];
+        Object[] obj = new Object[25];
+
+        WeakReference weakarray = new WeakReference(array); // array has only weak reference
+
+        // obj has both strong and weak ref and so should not get collected
+
+        WeakReference weakobj = new WeakReference(obj);
+        GCHandle objhandle = GCHandle.Alloc(obj, GCHandleType.Normal);
+
+        // ensuring GC.Collect() occurs even with /debug option
+        array = null;
+        obj = null;
+
+        GC.Collect();
+
+        Object target1 = weakarray.Target; // should be null
+        Object target2 = weakobj.Target;   // should be System.Object[]
+
+        Console.WriteLine("{0},{1}", target1, target2);
+
+        if ((target1 == null) && (target2 != null))
+        {
+            Console.WriteLine("Test for WeakReference.get_Target passed!");
+            return true;
+        }
+        else
+        {
+            Console.WriteLine("Test for WeakReference.get_Target failed!");
+            return false;
+        }
+    }
+
+    public bool SetTargetTest()
+    {
+        Dummy d1 = new Dummy(99);
+        Dummy d2 = new Dummy(66);
+
+        WeakReference wr = new WeakReference(d1);   // array has only weak reference
+        wr.Target = d2;                             // overwrite wr.Target with d2
+        Dummy d3 = (Dummy)wr.Target;                // get wr.Target
+        GC.KeepAlive(d2);                           // required so d2 doesn't get collected before setting d3
+
+        if (d3.val == 66)
+        {
+            // make sure d3 == d2, not d1
+            Console.WriteLine("Test for WeakReference.set_Target passed!");
+            return true;
+        }
+        else
+        {
+            Console.WriteLine("Test for WeakReference.set_Target failed!");
+            return false;
+        }
+    }
+
+    public static int Main()
+    {
+        bool passed1, passed2;
+
+        Test t = new Test();
+
+        passed1 = t.GetTargetTest();
+        passed2 = t.SetTargetTest();
+
+        if (passed1 && passed2)
+        {
+            Console.WriteLine("Test Passed!");
+            return 100;
+        }
+
+        Console.WriteLine("Test Failed!");
+        return 1;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/Target.csproj b/src/coreclr/tests/src/GC/API/WeakReference/Target.csproj
new file mode 100644 (file)
index 0000000..53825f8
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants);DESKTOP</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="Target.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/TrackResurrection.cs b/src/coreclr/tests/src/GC/API/WeakReference/TrackResurrection.cs
new file mode 100644 (file)
index 0000000..ea99f15
--- /dev/null
@@ -0,0 +1,38 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests WeakReference.TrackResurrection
+// Retrieves a boolean indicating whether objects are tracked.
+
+// TRUE: The reference will refer to the target until it is reclaimed by the Runtime
+//     (until collection).
+// FALSE: The reference will refer to the target until the first time it is detected
+//        to be unreachable by Runtime (until Finalization).
+
+
+using System;
+
+public class Test {
+    public static int Main() {
+        int[] array = new int[50];
+        Object obj = new Object();
+
+        WeakReference weak1 = new WeakReference(array,true);
+        WeakReference weak2 = new WeakReference(obj,false);
+
+        
+        bool ans1 = weak1.TrackResurrection;        
+        bool ans2 = weak2.TrackResurrection;    
+
+
+        if((ans1 == true) && (ans2 == false)) {
+            Console.WriteLine("Test for WeakReference.TrackResurrection passed!");
+            return 100;
+        }
+        else {
+            Console.WriteLine("Test for WeakReference.TrackResurrection failed!");
+            return 1;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/TrackResurrection.csproj b/src/coreclr/tests/src/GC/API/WeakReference/TrackResurrection.csproj
new file mode 100644 (file)
index 0000000..27e745c
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments></CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="TrackResurrection.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/app.config b/src/coreclr/tests/src/GC/API/WeakReference/app.config
new file mode 100644 (file)
index 0000000..6f7bbd9
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/multipleWRs.cs b/src/coreclr/tests/src/GC/API/WeakReference/multipleWRs.cs
new file mode 100644 (file)
index 0000000..e4c266f
--- /dev/null
@@ -0,0 +1,94 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+
+public class Test
+{
+
+    List<byte[]> strongRefs;
+    List<WeakReference> weakRefs;
+
+    public Test(int numElems, bool track)
+    {
+        strongRefs = new List<byte[]>();
+        weakRefs = new List<WeakReference>();
+
+        for (int i = 0; i < numElems; i++)
+        {
+            byte[] data = new byte[1000];
+            data[0] = 0xC;
+
+            strongRefs.Add(data);            
+            weakRefs.Add(new WeakReference(data, track));
+        }
+    }
+
+
+    public int Calculate()
+    {
+        int count = 0;
+        foreach (WeakReference w in weakRefs)
+        {
+            if (w.Target!=null)
+            {
+                ++count;
+            }
+        }
+        return count;
+    }
+
+
+    public static void Usage()
+    {
+        Console.WriteLine("USAGE: MultipleWR.exe <num objects> [track]");
+    }
+
+
+    public static int Main(string[] args)
+    {
+
+        int numElems = 0;
+        if ((args.Length==0) || (!Int32.TryParse(args[0], out numElems)))
+        {
+            Usage();
+            return 1;
+        }
+        
+        bool track = false;
+        if (args.Length==2)
+        {
+            track = (args[1].ToLower()=="track");
+        }
+        
+        
+
+        Test test = new Test(numElems, track);
+
+        GC.Collect();
+        GC.WaitForPendingFinalizers();
+        GC.Collect();
+
+        int count = test.Calculate();
+
+        Console.WriteLine("Number of live references: {0}", numElems);
+        Console.WriteLine("Number of live WeakReferences: {0}", count);
+        
+        // this KeepAlive is necessary so test isn't collected before we get the weakreference count
+        GC.KeepAlive(test); 
+
+        if (count!=numElems)
+        {                
+            Console.WriteLine("Test Failed");
+            return 1;
+        }            
+
+        Console.WriteLine("Test Passed");
+        return 100;            
+
+    }
+
+}
+
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/multipleWRs.csproj b/src/coreclr/tests/src/GC/API/WeakReference/multipleWRs.csproj
new file mode 100644 (file)
index 0000000..16a79a9
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>10000</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="multipleWRs.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/API/WeakReference/multipleWRs_1.csproj b/src/coreclr/tests/src/GC/API/WeakReference/multipleWRs_1.csproj
new file mode 100644 (file)
index 0000000..9c79fb2
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>10000 track</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="multipleWRs.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/Coverage/271010.cs b/src/coreclr/tests/src/GC/Coverage/271010.cs
new file mode 100644 (file)
index 0000000..64c1a19
--- /dev/null
@@ -0,0 +1,34 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/* DESCRIPTION: regression test for VSWhidbey 271010
+ *              Should throw OOM
+ */
+
+using System;
+using System.Runtime.CompilerServices;
+
+public class Test {
+
+    public static int Main() {
+
+        int[][] otherarray;
+
+        try
+        {
+            otherarray = new int[16384][];
+            for(int i=0;i<16384;i++)
+            {
+                otherarray[i] = new int[1024*500];
+            }
+        }
+        catch (System.OutOfMemoryException)
+        {
+            otherarray = null;
+            return 100;
+        }
+        return 1;
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Coverage/271010.csproj b/src/coreclr/tests/src/GC/Coverage/271010.csproj
new file mode 100644 (file)
index 0000000..60bb1b8
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="271010.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
index f9152b3..0784021 100644 (file)
     <Compile Include="LargeObjectAlloc.cs" />
   </ItemGroup>
   <ItemGroup>
-    <None Include="project.json" />
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
index 1ccf320..ea304ef 100644 (file)
     <Compile Include="LargeObjectAlloc2.cs" />
   </ItemGroup>
   <ItemGroup>
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
diff --git a/src/coreclr/tests/src/GC/Coverage/app.config b/src/coreclr/tests/src/GC/Coverage/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Coverage/concurrentspin2.cs b/src/coreclr/tests/src/GC/Coverage/concurrentspin2.cs
new file mode 100644 (file)
index 0000000..23edb8b
--- /dev/null
@@ -0,0 +1,184 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Diagnostics;
+using System.Threading;
+
+class PriorityTest
+{
+    private byte[][] old;
+    private byte[][] med;
+    private Random rand;
+
+    private int oldDataSize;
+    private int medDataSize;
+    private int iterCount;
+    private int meanAllocSize;
+    private int medTime;
+    private int youngTime;
+
+
+    public PriorityTest(int oldDataSize, int medDataSize,
+                        int iterCount, int meanAllocSize,
+                        int medTime, int youngTime)
+    {
+        rand = new Random(314159);
+        this.oldDataSize = oldDataSize;
+        this.medDataSize = medDataSize;
+        this.iterCount = iterCount;
+        this.meanAllocSize = meanAllocSize;
+        this.medTime = medTime;
+        this.youngTime = youngTime;
+    }
+
+    // creates initial arrays
+    void AllocTest(int oldDataSize, int medDataSize, int meanAllocSize)
+    {
+        old = new byte[oldDataSize][];
+        med = new byte[medDataSize][];
+
+        for (int i = 0; i < old.Length; i++)
+        {
+            old[i] = new byte[meanAllocSize];
+        }
+
+        for (int i = 0; i < med.Length; i++)
+        {
+            med[i] = new byte[meanAllocSize];
+        }
+    }
+
+    // churns data in the heap by replacing byte arrays with new ones of random length
+    // this should induce concurrent GCs
+    void SteadyState(int oldDataSize, int medDataSize,
+                        int iterCount, int meanAllocSize,
+                        int medTime, int youngTime)
+    {
+
+        for (int i = 0; i < iterCount; i++)
+        {
+            byte[] newarray = new byte[meanAllocSize];
+
+            if ((i % medTime) == 0)
+            {
+                old[rand.Next(0, old.Length)] = newarray;
+            }
+            if ((i % youngTime) == 0)
+            {
+                med[rand.Next(0, med.Length)] = newarray;
+            }
+            //if (((i % 5000) == 0) && (Thread.CurrentThread.Priority != ThreadPriority.Lowest))
+            //{
+            //    Thread.Sleep(200);
+            //}
+        }
+    }
+
+    // method that runs the test
+    public void RunTest()
+    {
+        for (int iteration = 0; iteration < iterCount; iteration++)
+        {
+            AllocTest(oldDataSize, medDataSize, meanAllocSize);
+
+            SteadyState(oldDataSize, medDataSize,
+                iterCount, meanAllocSize,
+                medTime, youngTime);
+
+            if (((iteration + 1) % 20) == 0)
+                Console.WriteLine("Thread: {1} Finished iteration {0}", iteration, System.Threading.Thread.CurrentThread.Name);
+        }
+
+    }
+
+}
+
+
+class ConcurrentRepro
+{
+
+    public static void Usage()
+    {
+        Console.WriteLine("Usage:");
+        Console.WriteLine("\t<num iterations> <num threads>");
+    }
+
+    public static int[] ParseArgs(string[] args)
+    {
+        int[] parameters = new int[2];
+
+        // set defaults
+        parameters[0] = 100;
+        parameters[1] = 4;
+
+        if (args.Length == 0)
+        {
+            //use defaults
+            Console.WriteLine("Using defaults: 100 iterations, 4 threads");
+            return parameters;
+        }
+        if (args.Length == parameters.Length)
+        {
+            for (int i = 0; i < args.Length; i++)
+            {
+                int j = 0;
+                if (!int.TryParse(args[i], out j))
+                {
+                    Usage();
+                    return null;
+                }
+                parameters[i] = j;
+            }
+
+            return parameters;
+        }
+
+        // incorrect number of arguments        
+        Usage();
+        return null;
+    }
+
+
+    public static int Main(string[] args)
+    {
+
+        // parse arguments
+        int[] parameters = ParseArgs(args);
+        if (parameters == null)
+        {
+            return 0;
+        }
+
+        // set process affinity to 1 to repro bug easier
+        //Process.GetCurrentProcess().ProcessorAffinity = (IntPtr)1;
+
+
+        PriorityTest priorityTest = new PriorityTest(1000000, 5000, parameters[0], 17, 30, 3);
+        ThreadStart startDelegate = new ThreadStart(priorityTest.RunTest);
+
+        // create threads
+        Thread[] threads = new Thread[parameters[1]];
+        for (int i = 0; i < threads.Length; i++)
+        {
+            threads[i] = new Thread(startDelegate);
+            threads[i].Name = String.Format("Thread{0}", i);
+            //if (i % 2 == 0)
+            //{
+            //    threads[i].Priority = ThreadPriority.Lowest;
+            //}
+            threads[i].Start();
+        }
+
+        // wait for threads to complete
+        for (int i = 0; i < threads.Length; i++)
+        {
+            threads[i].Join();
+        }
+
+        return 100;
+    }
+}
+
+
diff --git a/src/coreclr/tests/src/GC/Coverage/concurrentspin2.csproj b/src/coreclr/tests/src/GC/Coverage/concurrentspin2.csproj
new file mode 100644 (file)
index 0000000..7e63aff
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="ConcurrentSpin2.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Coverage/delete_next_card_table.cs b/src/coreclr/tests/src/GC/Coverage/delete_next_card_table.cs
new file mode 100644 (file)
index 0000000..ad0bd5c
--- /dev/null
@@ -0,0 +1,63 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/* TEST:        delete_next_card_table
+ * DESCRIPTION: gains 14 blocks in gc.cpp
+                mscorwks!WKS::delete_next_card_table: (7 blocks, 11 arcs)
+                mscorwks!SVR::delete_next_card_table: (7 blocks, 11 arcs)
+ */
+
+using System;
+using System.Collections;
+
+public class delete_next_card_table
+{
+    public static int Main()
+    {
+        new delete_next_card_table().DoMemoryChurn();
+        return 100;
+    }
+
+    // this function attempts to allocate & free large amounts
+    // of memory to ensure our objects remain pinned, don't get
+    // relocated, etc...
+    void DoMemoryChurn()
+    {
+
+        Random r = new Random();
+        for (int j = 0; j < 10; j++)
+        {
+            Console.Write("Churn loop {0}", j);
+
+            try
+            {
+                // arraylist keeps everything rooted until we run out of memory
+                //ArrayList al = new ArrayList();
+                object[] objArray = new object[32];
+                int len = 1;
+
+                for (int i = 0; i < 32; i++)        // todo: this should be based upon size of IntPtr (32 bits on 32 bit platforms, 64 on 64 bit platforms)
+                {
+                    Console.Write(".");
+
+                    if (i < 30)
+                    {
+                        // Random.Next cannot handle negative (0x80000000) numbers
+                        len *= 2;
+                    }
+                    //al.Add(new Guid[len + r.Next(len)]);
+                    objArray[i] = new Guid[len + r.Next(len)];
+                }
+            }
+            catch (OutOfMemoryException)
+            {
+                Console.WriteLine("OOM while Churning");
+                GC.Collect();
+            }
+
+            Console.WriteLine();
+        }
+    }
+}
+
diff --git a/src/coreclr/tests/src/GC/Coverage/delete_next_card_table.csproj b/src/coreclr/tests/src/GC/Coverage/delete_next_card_table.csproj
new file mode 100644 (file)
index 0000000..bd6d96f
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="delete_next_card_table.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Coverage/smalloom.cs b/src/coreclr/tests/src/GC/Coverage/smalloom.cs
new file mode 100644 (file)
index 0000000..a640c30
--- /dev/null
@@ -0,0 +1,72 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+//Regression test for Dev 10 bug 479239: GC hangs on x86 rather than throwing OOM
+using System;
+using System.Runtime;
+
+class TestClass
+{
+       public static int Main()
+       {
+        ByteArrayList list = new ByteArrayList();
+
+
+        try
+        {
+            while (true)
+            {
+                list.AddByteArray(84500);
+            }
+        }
+        catch (OutOfMemoryException)
+        {
+        }
+
+        Console.Write("NodesAllocated: ");
+        Console.WriteLine(list.NodeCount);
+        return 100;
+       }
+
+    class ByteArrayList
+    {
+        class Node
+        {
+            byte[] data = null;
+            int size = 0;
+            public Node next = null;
+
+            public Node(int Size)
+            {
+              data = new byte[Size];
+              size = Size;
+            }
+
+        }
+       
+        Node head;
+
+        public int NodeCount = 0;
+        public ByteArrayList()
+        {
+            head = null;
+        }
+
+        public void AddByteArray(int size)
+        {
+            Node newNode = new Node(size);
+
+            if (head == null)
+                head = newNode;
+            else
+            {
+                newNode.next = head;
+                head = newNode;
+            }
+            NodeCount++;
+        }
+    }
+
+}                      
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Coverage/smalloom.csproj b/src/coreclr/tests/src/GC/Coverage/smalloom.csproj
new file mode 100644 (file)
index 0000000..6f2fb9d
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="smalloom.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/BackgroundGC/app.config b/src/coreclr/tests/src/GC/Features/BackgroundGC/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Features/BackgroundGC/concurrentspin2.cs b/src/coreclr/tests/src/GC/Features/BackgroundGC/concurrentspin2.cs
new file mode 100644 (file)
index 0000000..23edb8b
--- /dev/null
@@ -0,0 +1,184 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Diagnostics;
+using System.Threading;
+
+class PriorityTest
+{
+    private byte[][] old;
+    private byte[][] med;
+    private Random rand;
+
+    private int oldDataSize;
+    private int medDataSize;
+    private int iterCount;
+    private int meanAllocSize;
+    private int medTime;
+    private int youngTime;
+
+
+    public PriorityTest(int oldDataSize, int medDataSize,
+                        int iterCount, int meanAllocSize,
+                        int medTime, int youngTime)
+    {
+        rand = new Random(314159);
+        this.oldDataSize = oldDataSize;
+        this.medDataSize = medDataSize;
+        this.iterCount = iterCount;
+        this.meanAllocSize = meanAllocSize;
+        this.medTime = medTime;
+        this.youngTime = youngTime;
+    }
+
+    // creates initial arrays
+    void AllocTest(int oldDataSize, int medDataSize, int meanAllocSize)
+    {
+        old = new byte[oldDataSize][];
+        med = new byte[medDataSize][];
+
+        for (int i = 0; i < old.Length; i++)
+        {
+            old[i] = new byte[meanAllocSize];
+        }
+
+        for (int i = 0; i < med.Length; i++)
+        {
+            med[i] = new byte[meanAllocSize];
+        }
+    }
+
+    // churns data in the heap by replacing byte arrays with new ones of random length
+    // this should induce concurrent GCs
+    void SteadyState(int oldDataSize, int medDataSize,
+                        int iterCount, int meanAllocSize,
+                        int medTime, int youngTime)
+    {
+
+        for (int i = 0; i < iterCount; i++)
+        {
+            byte[] newarray = new byte[meanAllocSize];
+
+            if ((i % medTime) == 0)
+            {
+                old[rand.Next(0, old.Length)] = newarray;
+            }
+            if ((i % youngTime) == 0)
+            {
+                med[rand.Next(0, med.Length)] = newarray;
+            }
+            //if (((i % 5000) == 0) && (Thread.CurrentThread.Priority != ThreadPriority.Lowest))
+            //{
+            //    Thread.Sleep(200);
+            //}
+        }
+    }
+
+    // method that runs the test
+    public void RunTest()
+    {
+        for (int iteration = 0; iteration < iterCount; iteration++)
+        {
+            AllocTest(oldDataSize, medDataSize, meanAllocSize);
+
+            SteadyState(oldDataSize, medDataSize,
+                iterCount, meanAllocSize,
+                medTime, youngTime);
+
+            if (((iteration + 1) % 20) == 0)
+                Console.WriteLine("Thread: {1} Finished iteration {0}", iteration, System.Threading.Thread.CurrentThread.Name);
+        }
+
+    }
+
+}
+
+
+class ConcurrentRepro
+{
+
+    public static void Usage()
+    {
+        Console.WriteLine("Usage:");
+        Console.WriteLine("\t<num iterations> <num threads>");
+    }
+
+    public static int[] ParseArgs(string[] args)
+    {
+        int[] parameters = new int[2];
+
+        // set defaults
+        parameters[0] = 100;
+        parameters[1] = 4;
+
+        if (args.Length == 0)
+        {
+            //use defaults
+            Console.WriteLine("Using defaults: 100 iterations, 4 threads");
+            return parameters;
+        }
+        if (args.Length == parameters.Length)
+        {
+            for (int i = 0; i < args.Length; i++)
+            {
+                int j = 0;
+                if (!int.TryParse(args[i], out j))
+                {
+                    Usage();
+                    return null;
+                }
+                parameters[i] = j;
+            }
+
+            return parameters;
+        }
+
+        // incorrect number of arguments        
+        Usage();
+        return null;
+    }
+
+
+    public static int Main(string[] args)
+    {
+
+        // parse arguments
+        int[] parameters = ParseArgs(args);
+        if (parameters == null)
+        {
+            return 0;
+        }
+
+        // set process affinity to 1 to repro bug easier
+        //Process.GetCurrentProcess().ProcessorAffinity = (IntPtr)1;
+
+
+        PriorityTest priorityTest = new PriorityTest(1000000, 5000, parameters[0], 17, 30, 3);
+        ThreadStart startDelegate = new ThreadStart(priorityTest.RunTest);
+
+        // create threads
+        Thread[] threads = new Thread[parameters[1]];
+        for (int i = 0; i < threads.Length; i++)
+        {
+            threads[i] = new Thread(startDelegate);
+            threads[i].Name = String.Format("Thread{0}", i);
+            //if (i % 2 == 0)
+            //{
+            //    threads[i].Priority = ThreadPriority.Lowest;
+            //}
+            threads[i].Start();
+        }
+
+        // wait for threads to complete
+        for (int i = 0; i < threads.Length; i++)
+        {
+            threads[i].Join();
+        }
+
+        return 100;
+    }
+}
+
+
diff --git a/src/coreclr/tests/src/GC/Features/BackgroundGC/concurrentspin2.csproj b/src/coreclr/tests/src/GC/Features/BackgroundGC/concurrentspin2.csproj
new file mode 100644 (file)
index 0000000..5e585cf
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="ConcurrentSpin2.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/BackgroundGC/foregroundgc.cs b/src/coreclr/tests/src/GC/Features/BackgroundGC/foregroundgc.cs
new file mode 100644 (file)
index 0000000..cd57f1c
--- /dev/null
@@ -0,0 +1,93 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+
+namespace ForegroundGC
+{
+    class ForegroundGC
+    {
+        static bool done = false;
+        static long maxAlloc = 1024 * 1024 * 1024;  //1GB max size
+        static int size = 30;
+        static int Main(string[] args)
+        {
+            if (args.Length > 0)
+            {
+                if ((args[0].CompareTo("-?") == 0) || (args[0].CompareTo("/?") == 0))
+                {
+                    Console.WriteLine("Usage: ForegroundGC.exe [max allocation in MB] [object size in bytes]");
+                    return 0;
+                }
+                else
+                {
+                    long maxAllocMB = Int32.Parse(args[0]);
+                    maxAlloc = maxAllocMB * 1024 * 1024;
+                }
+            }
+            if (args.Length > 1)
+            {
+                size = Int32.Parse(args[1]);
+            }
+            Console.WriteLine("Max allocation = {0} bytes; Objects size = {1}", maxAlloc, size);
+            List<byte[]> List1 = new List<byte[]>();
+            List<byte[]> List2 = new List<byte[]>();
+            long AllocCount = 0;  //bytes allocated
+            
+            while (AllocCount < maxAlloc)
+            {
+                byte[] b = new byte[size];
+                AllocCount += size;
+                List1.Add(b);
+               
+
+                byte[] b2 = new byte[size];
+                AllocCount += size;
+                List2.Add(b2);
+               
+            }
+            Thread t = new Thread(AllocateTemp);
+            t.Start();
+            List2.Clear();
+            Console.WriteLine("Finished allocating big array");
+            GC.Collect(2, GCCollectionMode.Optimized, false);
+
+            for (int k = 0; k < 2; k++)
+            {
+                for (int i = List1.Count - 1; i >= 0; i--)
+                {
+                    List2.Add(List1[i]);
+                    List1.RemoveAt(i);
+                }
+                for (int i = List2.Count - 1; i >= 0; i--)
+                {
+                    List1.Add(List2[i]);
+                    List2.RemoveAt(i);
+                }
+            }
+          
+            done = true;
+            t.Join();
+            Console.WriteLine("List count=" + List1.Count);
+
+            GC.KeepAlive(List1);
+            GC.KeepAlive(List2);
+
+            return 100;
+        }
+
+        static void AllocateTemp()
+        {
+            while (!done)
+            {
+                byte[] b = new byte[30];
+                byte[] b2 = new byte[100];
+            }
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Features/BackgroundGC/foregroundgc.csproj b/src/coreclr/tests/src/GC/Features/BackgroundGC/foregroundgc.csproj
new file mode 100644 (file)
index 0000000..5ee010d
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="ForegroundGC.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeio/app.config b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeio/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeio/finalizeio.cs b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeio/finalizeio.cs
new file mode 100644 (file)
index 0000000..9f07860
--- /dev/null
@@ -0,0 +1,103 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests IO in Finalize()
+
+using System;
+using System.IO;
+
+public class Test {
+
+    public class Dummy {
+
+        public static bool visited;
+
+        ~Dummy() {
+
+            Console.WriteLine("In Finalize() of Dummy");
+
+            visited=true;
+
+            try
+            {
+                FileStream test = new FileStream("temp.txt", FileMode.Open, FileAccess.Read);
+                using (StreamReader read = new StreamReader(test))
+                {
+                    // while not at the end of the file
+                    while (read.Peek() > -1)
+                        Console.WriteLine(read.ReadLine());
+                }
+            }
+            catch(Exception e)
+            {
+                Console.WriteLine("Exception handled: " + e);
+                visited=false;
+            }
+
+        }
+    }
+
+    public class CreateObj{
+        public Dummy obj;
+
+        public CreateObj() {
+            obj = new Dummy();
+        }
+
+        public bool RunTest() {
+
+            obj=null;
+            GC.Collect();
+
+            GC.WaitForPendingFinalizers();  // makes sure Finalize() is called.
+
+            return Dummy.visited;
+
+        }
+    }
+
+    public static int Main() {
+        CreateObj temp = new CreateObj();
+
+        using (StreamWriter writer = File.CreateText("temp.txt"))
+        {
+writer.WriteLine(@"***************** START ************************
+This is a test file for testing IO in Finalizers.
+Line 1
+Line 2
+Line 3
+Line 4
+Line 5
+Line 6
+Line 7
+Line 8
+Line 9
+Line 10
+Line 11
+Line 12
+Line 13
+Line 14
+Line 15
+Line 16
+Line 17
+Line 18
+Line 19
+Line 20
+Line 21
+Line 22
+Line 23
+******************* END *****************************");
+        }
+
+
+        if (temp.RunTest()) {
+            Console.WriteLine("Test for Finalize() & WaitForPendingFinalizers() passed!");
+            return 100;
+        }
+
+        Console.WriteLine("Test for Finalize() & WaitForPendingFinalizers() failed!");
+        return 1;
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeio/finalizeio.csproj b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeio/finalizeio.csproj
new file mode 100644 (file)
index 0000000..696e39d
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="FinalizeIO.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/app.config b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizearray.cs b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizearray.cs
new file mode 100644 (file)
index 0000000..373bf83
--- /dev/null
@@ -0,0 +1,59 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests Finalize() on array of objects
+
+using System;
+
+public class Test {
+
+       public class Dummy {
+               public static int count=0;
+               ~Dummy() {
+                       count++;
+               }
+       }
+
+       public class CreateObj {
+               public Dummy[] obj;
+
+               public CreateObj() {
+                       
+                       obj = new Dummy[10000];
+                       for(int i=0;i<10000;i++) {
+                               obj[i] = new Dummy();
+                       }
+               }
+
+               public bool RunTest() {
+                       obj=null;     // making sure collect is called even with /debug
+                       GC.Collect();
+                       GC.WaitForPendingFinalizers();
+               
+                       if(Dummy.count == 10000) {     // all objects in array finalized!
+                return true;
+                       }
+                       else {
+                return false;
+                       }
+               }
+       }
+
+       public static int Main() {
+
+               CreateObj temp = new CreateObj();
+
+        if (temp.RunTest())
+        {
+            Console.WriteLine("Test for Finalize() for array of objects passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for Finalize() for array of objects failed!");
+            return 1;
+        }
+
+       }
+}
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizearray.csproj b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizearray.csproj
new file mode 100644 (file)
index 0000000..ae688be
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="FinalizeArray.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizearraysleep.cs b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizearraysleep.cs
new file mode 100644 (file)
index 0000000..caf2be0
--- /dev/null
@@ -0,0 +1,59 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests Sleep in Finalizer for array of objects 
+
+using System;
+using System.Threading;
+
+public class Test {
+
+       public class Dummy {
+               public static int count=0;
+               ~Dummy() {
+                       count++;
+                       Thread.Sleep(1000);
+               }
+       }
+
+       public class CreateObj {
+               public Dummy[] obj;
+                public int ExitCode = 0;               
+
+               public CreateObj() {
+               obj = new Dummy[10];
+
+               for(int i=0;i<10;i++) {
+                       obj[i] = new Dummy();
+               }
+               }
+       
+               public void RunTest() {         
+
+               obj=null;     // making sure collect is called even with /debug
+               GC.Collect();
+               GC.WaitForPendingFinalizers();
+               
+               if(Dummy.count == 10) {     // all objects in array finalized!
+                       ExitCode = 100;
+                       //Console.WriteLine("Test for Finalize() for array of objects passed!");
+               }
+               else {
+                       ExitCode = 1;
+                       //Console.WriteLine("Test for Finalize() for array of objects failed!");
+               }
+               }
+       }
+
+       public static int Main() {
+               CreateObj temp = new CreateObj();
+               temp.RunTest();
+
+               if(temp.ExitCode==100)
+                       Console.WriteLine("Test for Finalize() for array of objects passed!");
+               else 
+                       Console.WriteLine("Test for Finalize() for array of objects failed!");
+                return temp.ExitCode;                          
+       }
+}
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizearraysleep.csproj b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizearraysleep.csproj
new file mode 100644 (file)
index 0000000..f4c6e5f
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="FinalizeArraySleep.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizedest.cs b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizedest.cs
new file mode 100644 (file)
index 0000000..5e7cbe2
--- /dev/null
@@ -0,0 +1,60 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests Finalize() and WaitForPendingFinalizers()
+
+using System;
+
+public class Test
+{
+
+    public class Dummy
+    {
+
+        public static bool visited;
+
+        ~Dummy()
+        {
+            Console.WriteLine("In Finalize() of Dummy");
+            visited=true;
+        }
+    }
+
+    public class CreateObj
+    {
+// disabling unused variable warning
+#pragma warning disable 0414
+        Dummy obj;
+#pragma warning restore 0414
+
+        public CreateObj()
+        {
+            obj = new Dummy();
+        }
+
+        public bool RunTest()
+        {
+            obj=null;
+            GC.Collect();
+
+            GC.WaitForPendingFinalizers();  // makes sure Finalize() is called.
+
+            return Dummy.visited;
+        }
+    }
+
+    public static int Main()
+    {
+        CreateObj temp = new CreateObj();
+
+        if (temp.RunTest())
+        {
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+        Console.WriteLine("Test Failed");
+        return 1;
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizedest.csproj b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizedest.csproj
new file mode 100644 (file)
index 0000000..67b6120
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="FinalizeDest.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizedirectedgraph.cs b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizedirectedgraph.cs
new file mode 100644 (file)
index 0000000..8d486f2
--- /dev/null
@@ -0,0 +1,262 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Build a Directed Graph with 10 nodes
+
+namespace Default {
+
+using System;
+
+public class Graph
+{
+       private Vertex Vfirst = null;
+       private Vertex Vlast = null;
+       private Edge Efirst = null;
+       private Edge Elast = null;
+       private int WeightSum = 0;
+       
+       public static int Nodes;
+       
+
+       public Graph(int n) { Nodes = n;}
+
+       public void SetWeightSum() {
+               Edge temp = Efirst;
+               WeightSum = 0;
+               while(temp != null) {
+                       WeightSum += temp.Weight;
+                       temp = temp.Next;
+               }
+       }
+       
+       public int GetWeightSum() {
+               return WeightSum;
+       }
+               
+       public void BuildEdge(int v1,int v2) {
+               Vertex n1 = null,n2 = null;
+               Vertex temp = Vfirst;
+               
+               while(temp != null) {
+            if (v1 == temp.Name)
+            {
+                               //found 1st node..
+                               n1 = temp;
+                               break;
+                       }
+                       else temp = temp.Next;
+               }
+               
+               //check if edge already exists
+               for(int i=0;i<n1.Num_Edges;i++) {
+                       
+            if (v2 == n1.Adjacent[i].Name) return;
+               }
+
+               temp = Vfirst;
+               while(temp != null) {
+            if (v2 == temp.Name)
+            {
+                               //found 2nd node..
+                               n2 = temp;
+                               break;
+                       }
+                       else temp = temp.Next;
+               }
+               
+               n1.Adjacent[n1.Num_Edges++]=n2;
+               
+               Edge temp2 = new Edge(n1,n2);
+                       if(Efirst==null) {
+                               Efirst = temp2;
+                               Elast = temp2;
+                       }
+                       else {
+                               temp2.AddEdge(Elast,temp2);
+                               Elast = temp2;
+                       }
+       }
+       
+       public void BuildGraph() {
+               
+               // Build Nodes  
+               Console.WriteLine("Building Vertices...");
+               for(int i=0;i< Nodes; i++) {
+                       Vertex temp = new Vertex(i);
+                       if(Vfirst==null) {
+                            Vfirst = temp;
+                            Vlast = temp;
+                       }
+                       else {
+                            temp.AddVertex(Vlast,temp);
+                            Vlast = temp;
+                        }
+               }
+               
+               // Build Edges
+               Console.WriteLine("Building Edges...");
+       
+               Int32 seed = System.Environment.TickCount;
+               Random rand = new Random(seed);
+               
+               for(int i=0;i< Nodes;i++) {
+                   
+                   int j = rand.Next(0,Nodes);
+                   for(int k=0;k<j;k++) {
+                      int v2;
+                      while((v2 = rand.Next(0,Nodes))==i);     //select a random node, also avoid self-loops
+                      BuildEdge(i,v2);                //build edge betn node i and v2
+                     
+                      
+                   }           
+               }
+       }
+
+
+       public void CheckIfReachable() {
+               int[] temp = new int[Nodes];
+               Vertex t1 = Vfirst;
+               
+               Console.WriteLine("Making all vertices reachable...");
+               while(t1 != null) {
+                       for(int i=0;i<t1.Num_Edges;i++) {
+                               if(temp[t1.Adjacent[i].Name] == 0)
+                                       temp[t1.Adjacent[i].Name]=1;
+                       }
+                       t1 = t1.Next;
+               }
+
+               for(int v2=0;v2<Nodes;v2++) {
+                       if(temp[v2]==0) {  //this vertex is not connected
+                               Int32 seed = System.Environment.TickCount;
+                               Random rand = new Random(seed);
+                               int v1;
+                               while((v1 = rand.Next(0,Nodes))==v2);     //select a random node, also avoid self-loops
+                               BuildEdge(v1,v2);
+                               temp[v2]=1;
+                       }
+               }
+               
+       }
+       
+
+       public void DeleteVertex() {
+
+               DeleteVertex(Vfirst);
+               
+       }
+
+       public void DeleteVertex(Vertex v) {
+               if(v == Vlast) {
+                       Vfirst=null;
+                       Vlast=null;
+                       GC.Collect();
+                       GC.WaitForPendingFinalizers();
+                       return;
+               }
+               Vertex temp = v.Next;
+               v=null;
+               GC.Collect();
+               GC.WaitForPendingFinalizers();
+               DeleteVertex(temp);
+               temp=null;
+               GC.Collect();
+               GC.WaitForPendingFinalizers();
+               
+       }
+       
+}
+
+public class Vertex
+       {
+               public int Name;
+               //public bool Visited = false;
+               
+               public Vertex Next;
+               public Vertex[] Adjacent;
+               public Edge[] Edges;
+               public int Num_Edges = 0;
+               public static int count=0;
+
+               public Vertex(int val) {
+                       Name = val;
+                       Next = null;
+                       Adjacent = new Vertex[Graph.Nodes];     
+               }
+               
+               ~Vertex() {
+                       Console.WriteLine("In Finalize of Vertex");
+                       count++;
+                       if(count==100) {
+                               Test.exitCode=100;
+                       }
+               }
+
+               public void AddVertex(Vertex x, Vertex y) {
+                       x.Next = y;                             
+               }
+               
+               public void DeleteAdjacentEntry(int n) {
+                       int temp=Num_Edges;
+                       for(int i=0;i< temp;i++) {
+                               if(n == Adjacent[i].Name) {
+                                       for(int j=i;j<Num_Edges;j++) 
+                                               Adjacent[j] = Adjacent[j+1];
+                                       Num_Edges--;
+                                       return;
+                               }
+                       }
+               }
+       }
+
+
+public class Edge 
+       {
+               public int Weight;
+               public Vertex v1,v2;
+               public Edge Next;
+       
+               public Edge(Vertex n1, Vertex n2) {
+                       v1=n1;
+                       v2=n2;
+                       
+                       int seed = n1.Name+n2.Name;
+                       Random rand = new Random(seed);
+                       Weight = rand.Next(0,50);
+               }
+               
+               public void AddEdge(Edge x, Edge y) {
+                       x.Next = y;                             
+               }
+
+       }
+
+
+public class Test
+{
+  public static int exitCode;
+  public static int Main()
+  {
+       exitCode=1;
+
+       Console.WriteLine("Test should pass with ExitCode 100");
+       Console.WriteLine("Building Graph with 100 vertices...");
+       Graph MyGraph = new Graph(100);  // graph with 10 nodes
+
+       MyGraph.BuildGraph();    
+       MyGraph.CheckIfReachable();
+
+       Console.WriteLine("Deleting all vertices...");
+
+       MyGraph.DeleteVertex();
+
+       GC.Collect();
+       GC.WaitForPendingFinalizers();
+
+       Console.WriteLine("Done...");
+
+    return exitCode;
+  }
+}
+}
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizedirectedgraph.csproj b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizedirectedgraph.csproj
new file mode 100644 (file)
index 0000000..eb454c8
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="FinalizeDirectedGraph.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizeexcep.cs b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizeexcep.cs
new file mode 100644 (file)
index 0000000..c08cf6d
--- /dev/null
@@ -0,0 +1,72 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests Exception handling in Finalize() 
+
+using System;
+
+public class Test {
+
+       public class List {
+               public int val;
+               public List next;
+       }
+       public class Dummy {
+
+               public static bool visited;
+       
+               ~Dummy() {
+                       List lst = new List();
+                       Console.WriteLine("In Finalize() of Dummy");
+                       try {
+                               Console.WriteLine(lst.next.val);    // should throw nullreference exception
+                       } catch(NullReferenceException) {
+                Console.WriteLine("Caught NullReferenceException in Finalize()");                              
+                visited=true;
+                       }
+                       
+                       
+               }
+       }
+
+       public class CreateObj {
+               public Dummy obj;
+
+               public CreateObj() {
+                       obj = new Dummy();
+               }
+
+               public bool RunTest() {
+                       obj=null;
+                       GC.Collect();
+               
+                       GC.WaitForPendingFinalizers();  // makes sure Finalize() is called.
+
+                       if(Dummy.visited == true) {
+                return true;
+                       }
+                       else {
+                return false;
+                       }
+               }
+       }
+
+       public static int Main() {
+
+               CreateObj temp= new CreateObj();
+
+        if (temp.RunTest())
+        {
+            Console.WriteLine("Test for Exception handling in Finalize() passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for Exception handling in Finalize() failed!");
+            return 1;
+        }
+               
+               
+       }
+}
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizeexcep.csproj b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizeexcep.csproj
new file mode 100644 (file)
index 0000000..048f95b
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="FinalizeExcep.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizeinherit.cs b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizeinherit.cs
new file mode 100644 (file)
index 0000000..cfce1f6
--- /dev/null
@@ -0,0 +1,97 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests Finalize() with Inheritance
+
+using System;
+
+namespace One
+{
+    abstract class A
+    {
+
+    }
+
+    class B: A
+    {
+        ~B()
+        {
+            Console.WriteLine("In Finalize of B");
+        }
+    }
+
+    class C: B
+    {
+        public static int count=0;
+        ~C()
+        {
+            Console.WriteLine("In Finalize of C");
+            count++;
+        }
+    }
+}
+
+namespace Two
+{
+    using One;
+    class D: C
+    {
+    }
+}
+
+namespace Three {
+    using One;
+    using Two;
+
+    class CreateObj
+    {
+
+// disabling unused variable warning
+#pragma warning disable 0414
+        B b;
+        D d;
+#pragma warning restore 0414
+        C c;
+
+        public CreateObj()
+        {
+            b = new B();
+            c = new C();
+            d = new D();
+        }
+
+        public bool RunTest()
+        {
+            A a = c;
+
+            d=null;
+            b=null;
+            a=null;
+            c=null;
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            return (C.count == 2);
+        }
+    }
+
+    class Test
+    {
+        static int Main()
+        {
+            CreateObj temp = new CreateObj();
+
+            if (temp.RunTest())
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            Console.WriteLine("Test Failed");
+            return 1;
+
+        }
+    }
+
+}
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizeinherit.csproj b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizeinherit.csproj
new file mode 100644 (file)
index 0000000..09810c4
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="FinalizeInherit.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizenested.cs b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizenested.cs
new file mode 100644 (file)
index 0000000..2eb6719
--- /dev/null
@@ -0,0 +1,126 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests Nested Finalize()
+
+using System;
+using System.Threading;
+
+public class Test {
+
+    public class D
+    {
+        ~D()
+        {
+            Console.WriteLine("In Finalize() of D");
+            Thread.Sleep(1000);
+        }
+    }
+
+    public class C
+    {
+        public D d;
+
+        public C()
+        {
+            d = new D();
+        }
+
+        ~C()
+        {
+            Console.WriteLine("In Finalize() of C");
+            d=null;
+            Thread.Sleep(1000);
+        }
+    }
+
+    public class B
+    {
+        public C c;
+
+        public B()
+        {
+            c = new C();
+        }
+
+        ~B()
+        {
+            Console.WriteLine("In Finalize() of B");
+            c=null;
+            Thread.Sleep(1000);
+        }
+    }
+
+    public class A
+    {
+        public B b;
+
+        public A()
+        {
+            b = new B();
+        }
+
+        ~A()
+        {
+            Console.WriteLine("In Finalize() of A");
+            b=null;
+            Thread.Sleep(1000);
+        }
+    }
+
+    public class Dummy {
+
+        public A a;
+        public static bool visited;
+
+        public Dummy()
+        {
+            a = new A();
+        }
+
+        ~Dummy()
+        {
+            Console.WriteLine("In Finalize() of Dummy");
+            a=null;
+            visited=true;
+        }
+    }
+
+    public class CreateObj
+    {
+// disabling unused variable warning
+#pragma warning disable 0414
+        Dummy obj;
+#pragma warning restore 0414
+
+        public CreateObj()
+        {
+            obj=new Dummy();
+        }
+
+        public bool RunTest()
+        {
+            obj=null;
+            GC.Collect();
+
+            GC.WaitForPendingFinalizers();  // makes sure Finalize() is called.
+
+            return Dummy.visited;
+        }
+    }
+
+    public static int Main() {
+
+        CreateObj temp = new CreateObj();
+
+        if (temp.RunTest())
+        {
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+        Console.WriteLine("Test Failed");
+        return 1;
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizenested.csproj b/src/coreclr/tests/src/GC/Features/Finalizer/finalizeother/finalizenested.csproj
new file mode 100644 (file)
index 0000000..2b27830
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="FinalizeNested.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
index 62c661f..57e841f 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
index 34a16eb..c37c71b 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
index 0cf3a43..f0e5b3e 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
diff --git a/src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit-finalize.cs b/src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit-finalize.cs
new file mode 100644 (file)
index 0000000..0e511a3
--- /dev/null
@@ -0,0 +1,197 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+//This is modeled after a server executing requests
+//which pin some of their newly allocated objects.
+using System;
+using System.Threading;
+using System.Runtime.InteropServices;
+using System.Security;
+
+namespace Fragment
+{
+    [SecuritySafeCritical]
+    public class Request
+    {
+        Object[] survivors;
+        GCHandle pin;
+
+        [SecuritySafeCritical]
+        public Request()
+        {
+            survivors = new Object[1 + (int)(Test.AllocationVolume*Test.SurvivalRate)/100];
+            int i = 0;
+            int volume = 0;
+
+            //allocate half of the request size.
+            while (volume < Test.AllocationVolume/2)
+            {
+                volume += AllocHalfVolume(++i, Test.SurvivalRate);
+            }
+
+            //allocate one pinned buffer
+            pin = GCHandle.Alloc(new byte[100], GCHandleType.Pinned);
+
+            //allocate the rest of the request
+            while (volume < Test.AllocationVolume)
+            {
+                volume += AllocHalfVolume(++i, Test.SurvivalRate);
+            }
+
+        }
+
+        // unpins and releases the pinned buffer
+        [SecuritySafeCritical]
+        ~Request()
+        {
+            pin.Free();
+        }
+
+        [SecuritySafeCritical]
+        private int AllocHalfVolume(int index, float survFraction)
+        {
+            int allocSurv = Test.Rand.Next(100, 2000 + 2*index);
+            int alloc = (int)(allocSurv / survFraction) - allocSurv;
+
+            // create garbage
+            int garbage=0;
+            while (garbage < alloc)
+            {
+                int size = Test.Rand.Next(10, 200+2*garbage);
+                Object x = new byte[size];
+                garbage+=size;
+            }
+            survivors[index] = new byte[allocSurv];
+            return allocSurv + alloc;
+        }
+
+    }
+
+    public class Test
+    {
+
+        public static Random Rand;
+        public static int NumRequests = 0;
+        public static int AllocationVolume = 0;
+        public static float SurvivalRate = 0.6f;
+
+        public void Go()
+        {
+            int steadyStateFactor = 5;
+            Request[] requests = new Request[NumRequests];
+            int instRequests = 0;
+            int totalReqs = 0;
+            int nreqsToSteady = 0;
+            bool done = false;
+
+            while (!done)
+            {
+                totalReqs++;
+                int i = Rand.Next(0, NumRequests);
+                if (requests[i] != null)
+                {
+                    requests[i] = null;
+                }
+                else
+                {
+                    instRequests++;
+                }
+                requests[i] = new Request();
+
+                if (instRequests == NumRequests)
+                {
+                    if (nreqsToSteady == 0)
+                    {
+                        nreqsToSteady = totalReqs;
+                        Console.WriteLine ("Took {0} iterations to reach steady state", nreqsToSteady);
+                    }
+                    else if (totalReqs == steadyStateFactor*nreqsToSteady)
+                    {
+                        done = true;
+                    }
+                }
+            }
+
+            for (int i = 0; i < NumRequests; i++)
+            {
+                requests[i] = null;
+            }
+
+        }
+
+
+        public static void Usage()
+        {
+            Console.WriteLine("Usage:");
+            Console.WriteLine("Fragment <num iterations> <num requests> <allocation volume> [random seed]");
+        }
+
+
+        static public int Main (String[] args)
+        {
+            int numIterations = 0;
+            int randomSeed = 0;
+
+            switch (args.Length)
+            {
+                case 0:
+                    // use defaults
+                    numIterations = 1;
+                    NumRequests = 1200;
+                    AllocationVolume = 100000;
+                    randomSeed = (int)DateTime.Now.Ticks;
+                    Console.WriteLine("Using defaults: {0} {1} {2}", numIterations, NumRequests, AllocationVolume);
+
+                    break;
+                case 3:
+                case 4:
+                    if ( (!Int32.TryParse(args[0], out numIterations)) ||
+                         (!Int32.TryParse(args[1], out NumRequests)) ||
+                         (!Int32.TryParse(args[2], out AllocationVolume)) )
+                    {
+                        goto default;
+                    }
+
+                    if (args.Length==4)
+                    {
+                        if (!Int32.TryParse(args[3], out randomSeed))
+                        {
+                            goto default;
+                        }
+                    }
+                    else
+                    {
+                        randomSeed = (int)DateTime.Now.Ticks;
+                    }
+
+                    break;
+                default:
+                    Usage();
+                    return 1;
+            }
+
+            Console.WriteLine("Using random seed: {0}", randomSeed );
+            Rand = new Random(randomSeed);
+
+            try
+            {
+                for (int j=0; j<numIterations; j++)
+                {
+                    Test t = new Test();
+                    t.Go();
+                }
+            }
+            catch (OutOfMemoryException)
+            {
+                Console.WriteLine("OOM");
+                Console.WriteLine(GC.GetTotalMemory(false));
+                Console.WriteLine("Test Failed");
+                return 1;
+            }
+
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit-finalize.csproj b/src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit-finalize.csproj
new file mode 100644 (file)
index 0000000..32fe397
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="bestfit-finalize.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit-threaded.cs b/src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit-threaded.cs
new file mode 100644 (file)
index 0000000..0b02803
--- /dev/null
@@ -0,0 +1,195 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+//This is modeled after a server executing requests
+//which pin some of their newly allocated objects.
+using System;
+using System.Threading;
+using System.Runtime.InteropServices;
+using System.Security;
+
+public class one_pass
+{
+    public Random r = new Random(request.RandomSeed);
+
+[SecuritySafeCritical]
+public one_pass ()
+    {
+
+        int n_requests = 1200;
+        int allocation_volume = 100000;
+        float survival_rate = 0.6f;
+        int steady_state_factor = 5;
+        request[] requests = new request[n_requests];
+        int inst_requests = 0;
+        int total_reqs = 0;
+        int nreqs_to_steady = 0;
+        while (true)
+        {
+            total_reqs++;
+            int i = r.Next (0, n_requests);
+            if (requests [i] != null)
+            {
+                requests [i].retire();
+            }
+            else
+            {
+                inst_requests++;
+            }
+            requests [i] = new request (allocation_volume, survival_rate);
+
+            if (inst_requests == n_requests)
+            {
+                if (nreqs_to_steady == 0)
+                {
+                    nreqs_to_steady = total_reqs;
+                    Console.WriteLine ("took {0} iteration to reach steady state",
+                                       nreqs_to_steady);
+                } else if (total_reqs == steady_state_factor*nreqs_to_steady)
+                {
+                    break;
+                }
+            }
+        }
+
+        for (int i = 0; i < n_requests; i++)
+        {
+            requests[i].retire();
+        }
+
+    }
+}
+
+
+public class request
+{
+    Object[] survivors;
+    GCHandle pin;
+    public Random r = new Random(request.RandomSeed);
+
+    [SecuritySafeCritical]
+    public request (int alloc_volume, float surv_fraction)
+    {
+        survivors = new Object [1 + (int)(alloc_volume*surv_fraction)/100];
+        int i = 0;
+        int volume = 0;
+        //allocate half of the request size.
+        while (volume < alloc_volume/2)
+        {
+            int alloc_surv = r.Next (100, 2000 + 2*i);
+            //Console.WriteLine ("alloc_surv {0}", alloc_surv);
+            int alloc = (int)(alloc_surv / surv_fraction) - alloc_surv;
+            //Console.WriteLine ("alloc {0}", alloc);
+            int j = 0;
+            while (j < alloc)
+            {
+                int s = r.Next (10, 200+2*j);
+
+                Object x = new byte [s];
+                j+=s;
+            }
+            survivors [i] = new byte [alloc_surv];
+            i++;
+            volume += alloc_surv + alloc;
+        }
+        //allocate one pinned buffer
+        pin = GCHandle.Alloc (new byte [100], GCHandleType.Pinned);
+        //allocate the rest of the request
+        while (volume < alloc_volume)
+        {
+            int alloc_surv = r.Next (100, 2000 + 2*i);
+            //Console.WriteLine ("alloc_surv {0}", alloc_surv);
+            int alloc = (int)(alloc_surv / surv_fraction) - alloc_surv;
+            //Console.WriteLine ("alloc {0}", alloc);
+
+            survivors [i] = new byte [alloc_surv];
+
+            int j = 0;
+            while (j < alloc)
+            {
+                int s = r.Next (10, 200+2*j);
+
+                Object x = new byte [s];
+                j+=s;
+            }
+            i++;
+            volume += alloc_surv + alloc;
+        }
+
+    }
+
+    [SecuritySafeCritical]
+    public void retire()
+    {
+        pin.Free();
+    }
+
+    public static void Usage()
+    {
+        Console.WriteLine("Usage:");
+        Console.WriteLine("Fragment <num threads> [random seed]");
+    }
+
+    static public int RandomSeed;
+
+    static public int Main (String[] args)
+    {
+
+        int numThreads = 0;
+
+
+        switch (args.Length)
+        {
+            case 0:
+                // use defaults
+                numThreads = 4;
+                RandomSeed = (int)DateTime.Now.Ticks;
+                Console.WriteLine("Using defaults: {0}", numThreads);
+                break;
+            case 1:
+            case 2:
+                if (!Int32.TryParse(args[0], out numThreads))
+                {
+                    goto default;
+                }
+                if (args.Length==2)
+                {
+                    if (!Int32.TryParse(args[1], out RandomSeed))
+                    {
+                        goto default;
+                    }
+                }
+                else
+                {
+                    RandomSeed = (int)DateTime.Now.Ticks;
+                }
+                break;
+            default:
+                Usage();
+                return 1;
+        }
+
+        Console.WriteLine("Using random seed: {0}", RandomSeed );
+
+        Console.WriteLine("Starting Threads...");
+/*        Thread[] threads = new Thread[numThreads];
+        for (int i=0; i<threads.Length; i++)
+        {
+            threads[i] = new Thread(new ThreadStart(delegate{ one_pass r = new one_pass();  }));
+            threads[i].Start();
+        }
+
+        Console.WriteLine("Joining Threads...");
+        for (int i=0; i<threads.Length; i++)
+        {
+            threads[i].Join();
+        }
+*/
+new one_pass();
+        Console.WriteLine("Test Passed");
+        return 100;
+    }
+}
+
+
diff --git a/src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit-threaded.csproj b/src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit-threaded.csproj
new file mode 100644 (file)
index 0000000..b813b7e
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="bestfit-threaded.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit.cs b/src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit.cs
new file mode 100644 (file)
index 0000000..4df7a0f
--- /dev/null
@@ -0,0 +1,196 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+//This is modeled after a server executing requests
+//which pin some of their newly allocated objects.
+using System;
+using System.Threading;
+using System.Runtime.InteropServices;
+using System.Security;
+
+namespace Fragment
+{
+    public class Request
+    {
+        Object[] survivors;
+        GCHandle pin;
+
+        [SecuritySafeCritical]
+        public Request()
+        {
+            survivors = new Object[1 + (int)(Test.AllocationVolume*Test.SurvivalRate)/100];
+            int i = 0;
+            int volume = 0;
+
+            //allocate half of the request size.
+            while (volume < Test.AllocationVolume/2)
+            {
+                volume += AllocHalfVolume(++i, Test.SurvivalRate);
+            }
+
+            //allocate one pinned buffer
+            pin = GCHandle.Alloc(new byte[100], GCHandleType.Pinned);
+
+            //allocate the rest of the request
+            while (volume < Test.AllocationVolume)
+            {
+                volume += AllocHalfVolume(++i, Test.SurvivalRate);
+            }
+
+        }
+
+        // unpins and releases the pinned buffer
+        [SecuritySafeCritical]
+        public void Retire()
+        {
+            pin.Free();
+        }
+
+        [SecuritySafeCritical]
+        private int AllocHalfVolume(int index, float survFraction)
+        {
+            int allocSurv = Test.Rand.Next(100, 2000 + 2*index);
+            int alloc = (int)(allocSurv / survFraction) - allocSurv;
+
+            // create garbage
+            int garbage=0;
+            while (garbage < alloc)
+            {
+                int size = Test.Rand.Next(10, 200+2*garbage);
+                Object x = new byte[size];
+                garbage+=size;
+            }
+            survivors[index] = new byte[allocSurv];
+            return allocSurv + alloc;
+        }
+
+    }
+
+    public class Test
+    {
+
+        public static Random Rand;
+        public static int NumRequests = 0;
+        public static int AllocationVolume = 0;
+        public static float SurvivalRate = 0.6f;
+
+        public void Go()
+        {
+            int steadyStateFactor = 5;
+            Request[] requests = new Request[NumRequests];
+            int instRequests = 0;
+            int totalReqs = 0;
+            int nreqsToSteady = 0;
+            bool done = false;
+
+            while (!done)
+            {
+                totalReqs++;
+                int i = Rand.Next(0, NumRequests);
+                if (requests[i] != null)
+                {
+                    requests[i].Retire();
+                }
+                else
+                {
+                    instRequests++;
+                }
+                requests[i] = new Request();
+
+                if (instRequests == NumRequests)
+                {
+                    if (nreqsToSteady == 0)
+                    {
+                        nreqsToSteady = totalReqs;
+                        Console.WriteLine ("Took {0} iterations to reach steady state", nreqsToSteady);
+                    }
+                    else if (totalReqs == steadyStateFactor*nreqsToSteady)
+                    {
+                        done = true;
+                    }
+                }
+            }
+
+            for (int i = 0; i < NumRequests; i++)
+            {
+                requests[i].Retire();
+            }
+
+        }
+
+
+        public static void Usage()
+        {
+            Console.WriteLine("Usage:");
+            Console.WriteLine("Fragment <num iterations> <num requests> <allocation volume> [random seed]");
+        }
+
+
+        static public int Main (String[] args)
+        {
+            int numIterations = 0;
+            int randomSeed = 0;
+
+            switch (args.Length)
+            {
+                case 0:
+                    // use defaults
+                    numIterations = 1;
+                    NumRequests = 1200;
+                    AllocationVolume = 100000;
+                    randomSeed = (int)DateTime.Now.Ticks;
+                    Console.WriteLine("Using defaults: {0} {1} {2}", numIterations, NumRequests, AllocationVolume);
+
+                    break;
+                case 3:
+                case 4:
+                    if ( (!Int32.TryParse(args[0], out numIterations)) ||
+                         (!Int32.TryParse(args[1], out NumRequests)) ||
+                         (!Int32.TryParse(args[2], out AllocationVolume)) )
+                    {
+                        goto default;
+                    }
+
+                    if (args.Length==4)
+                    {
+                        if (!Int32.TryParse(args[3], out randomSeed))
+                        {
+                            goto default;
+                        }
+                    }
+                    else
+                    {
+                        randomSeed = (int)DateTime.Now.Ticks;
+                    }
+
+                    break;
+                default:
+                    Usage();
+                    return 1;
+            }
+
+            Console.WriteLine("Using random seed: {0}", randomSeed );
+            Rand = new Random(randomSeed);
+
+            try
+            {
+                for (int j=0; j<numIterations; j++)
+                {
+                    Test t = new Test();
+                    t.Go();
+                }
+            }
+            catch (OutOfMemoryException)
+            {
+                Console.WriteLine("OOM");
+                Console.WriteLine(GC.GetTotalMemory(false));
+                Console.WriteLine("Test Failed");
+                return 1;
+            }
+
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit.csproj b/src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit.csproj
new file mode 100644 (file)
index 0000000..3540e68
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>1 1000 50000</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="bestfit.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit_1.csproj b/src/coreclr/tests/src/GC/Features/HeapExpansion/bestfit_1.csproj
new file mode 100644 (file)
index 0000000..5e2938f
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>1 1000 50000</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <!-- Set to 'Full' if the Debug? column is marked in the spreadsheet. Leave blank otherwise. -->
+    <DebugType>PdbOnly</DebugType>
+    <NoLogo>True</NoLogo>
+    <DefineConstants>$(DefineConstants)</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="bestfit.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup> 
+</Project>
diff --git a/src/coreclr/tests/src/GC/Features/HeapExpansion/expandheap.cs b/src/coreclr/tests/src/GC/Features/HeapExpansion/expandheap.cs
new file mode 100644 (file)
index 0000000..dee19eb
--- /dev/null
@@ -0,0 +1,38 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*
+This test stimulates heap expansion on the finalizer thread
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+public class Test
+{
+
+
+
+    public static int Main()
+    {
+        Console.WriteLine("First Alloc");
+        GCUtil.Alloc(1024*1024*4, 30);
+        GCUtil.FreeNonPins();
+        GC.Collect();
+
+        Console.WriteLine("Second Alloc");
+        GCUtil.Alloc(1024*1024*4, 50);
+        GCUtil.FreeNonPins();
+        GC.Collect();
+        GCUtil.FreePins();
+
+        Console.WriteLine("Test passed");
+        return 100;
+
+    }
+
+   
+
+}
diff --git a/src/coreclr/tests/src/GC/Features/HeapExpansion/expandheap.csproj b/src/coreclr/tests/src/GC/Features/HeapExpansion/expandheap.csproj
new file mode 100644 (file)
index 0000000..9722347
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="ExpandHeap.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="GCUtil_HeapExpansion.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/HeapExpansion/plug.cs b/src/coreclr/tests/src/GC/Features/HeapExpansion/plug.cs
new file mode 100644 (file)
index 0000000..ac029b4
--- /dev/null
@@ -0,0 +1,86 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+using System.Collections.Generic;
+using System.Security;
+
+public class Test
+{
+
+    public static void Usage()
+    {
+        Console.WriteLine("USAGE:");
+        Console.WriteLine("plug.exe [numIterations]");
+    }
+
+    [SecuritySafeCritical]
+    public static int Main(string[] args)
+    {
+
+        int size = 10000;
+        int power = 20;
+        int numIterations = 0;
+        GCHandle[] list = new GCHandle[size];
+
+        if (args.Length == 0)
+        {
+            //using defaults
+            numIterations = 100;
+        }
+        else if (args.Length == 1)
+        {
+            if (!Int32.TryParse(args[0], out numIterations))
+            {
+                Usage();
+                return 1;
+            }
+        }
+        else
+        {
+            Usage();
+            return 1;
+        }
+
+        Console.WriteLine("Running {0} iterations", numIterations);
+
+        for (int j=0; j<numIterations; j++)
+        {
+            for (int i=0; i<size; i++)
+            {
+                GCHandleType type = GCHandleType.Normal;
+
+                if (i%5==0)
+                {
+                    // pin every 5th handle
+                    type = GCHandleType.Pinned;
+                }
+
+                if (!list[i].IsAllocated)
+                {
+                    try
+                    {
+                        byte[] b = new byte[(int)Math.Pow(2,(i%power))];
+                        list[i] = (GCHandle.Alloc(b, type));
+                    }
+                    catch (OutOfMemoryException)
+                    {
+                        Console.WriteLine("OOM");
+                        Console.WriteLine("Heap size: {0}", GC.GetTotalMemory(false));
+                        Console.WriteLine("Trying to allocate array of size: {0}", Math.Pow(2,(i%power)));
+                    }
+                }
+                else
+                {
+                    list[i].Free();
+                }
+            }
+
+        }
+
+        return 100;
+    }
+}
+
diff --git a/src/coreclr/tests/src/GC/Features/HeapExpansion/plug.csproj b/src/coreclr/tests/src/GC/Features/HeapExpansion/plug.csproj
new file mode 100644 (file)
index 0000000..c31c6a1
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="plug.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/HeapExpansion/pluggaps.cs b/src/coreclr/tests/src/GC/Features/HeapExpansion/pluggaps.cs
new file mode 100644 (file)
index 0000000..499453d
--- /dev/null
@@ -0,0 +1,51 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*
+This test fragments the heap with ~50 byte holes, then allocates ~50 byte objects to plug them
+*/
+
+using System;
+using System.Runtime.InteropServices;
+using System.Collections.Generic;
+
+public class Test
+{
+    public static List<GCHandle> gchList = new List<GCHandle>();
+    public static List<byte[]> bList = new List<byte[]>();
+
+    public static int Main()
+    {
+
+        Console.WriteLine("Beginning phase 1");
+        GCUtil.AllocWithGaps();
+
+        Console.WriteLine("phase 1 complete");
+
+
+        // losing all live references to the unpinned byte arrays
+        // this will fragment the heap with ~50 byte holes
+        GCUtil.FreeNonPins();
+        GC.Collect();
+        GC.WaitForPendingFinalizers();
+        GC.Collect();
+
+        Console.WriteLine("Beginning phase 2");
+
+        bList = new List<byte[]>();
+        for (int i=0; i<1024*1024; i++)
+        {
+            byte[] unpinned = new byte[50];
+            bList.Add(unpinned);
+
+        }
+
+        Console.WriteLine("phase 2 complete");
+
+        GC.KeepAlive(gchList);
+        GC.KeepAlive(bList);
+
+        return 100;
+    }
+}
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/HeapExpansion/pluggaps.csproj b/src/coreclr/tests/src/GC/Features/HeapExpansion/pluggaps.csproj
new file mode 100644 (file)
index 0000000..474b393
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="PlugGaps.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="GCUtil_HeapExpansion.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/HeapExpansion/project.json b/src/coreclr/tests/src/GC/Features/HeapExpansion/project.json
deleted file mode 100644 (file)
index 14c11d2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "dependencies": {
-    "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
-    "System.Collections": "4.0.10",
-    "System.Collections.NonGeneric": "4.0.1-beta-23302",
-    "System.Collections.Specialized": "4.0.1-beta-23302",
-    "System.ComponentModel": "4.0.1-beta-23302",
-    "System.Console": "4.0.0-beta-23302",
-    "System.Diagnostics.Process": "4.0.0-beta-23302",
-    "System.Globalization": "4.0.10",
-    "System.Globalization.Calendars": "4.0.0",
-    "System.IO": "4.0.10",
-    "System.IO.FileSystem": "4.0.0",
-    "System.IO.FileSystem.Primitives": "4.0.0",
-    "System.Linq": "4.0.1-beta-23302",
-    "System.Linq.Queryable": "4.0.1-beta-23302",
-    "System.Reflection": "4.0.10",
-    "System.Reflection.Primitives": "4.0.0",
-    "System.Runtime": "4.0.20",
-    "System.Runtime.Extensions": "4.0.10",
-    "System.Runtime.Handles": "4.0.0",
-    "System.Runtime.InteropServices": "4.0.20",
-    "System.Runtime.Loader": "4.0.0-beta-23302",
-    "System.Text.Encoding": "4.0.10",
-    "System.Threading": "4.0.10",
-    "System.Xml.ReaderWriter": "4.0.11-beta-23302",
-    "System.Xml.XDocument": "4.0.11-beta-23302",
-    "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
-  },
-  "frameworks": {
-    "dnxcore50": {}
-  }
-}
diff --git a/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/app.config b/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivearray.cs b/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivearray.cs
new file mode 100644 (file)
index 0000000..6511db3
--- /dev/null
@@ -0,0 +1,46 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests KeepAlive() for array of objects
+
+using System;
+
+public class Test {
+
+       public class Dummy {
+
+               public static bool visited;
+               ~Dummy() {
+                       //Console.WriteLine("In Finalize() of Dummy");  
+                       visited=true;
+               }
+       }
+
+       public static int Main() {
+
+        int returnValue = 0;
+               Dummy[] obj = new Dummy[100];
+
+               for(int i=0;i<100;i++) {
+                       obj[i]= new Dummy();
+               }
+                       
+               GC.Collect();
+               GC.WaitForPendingFinalizers();
+               
+                               
+               if(Dummy.visited == false) {  // has not visited the Finalize()
+            returnValue = 100;
+                       Console.WriteLine("Test for KeepAlive() passed!");
+               }
+               else {
+            returnValue = 1;
+                       Console.WriteLine("Test for KeepAlive() failed!");
+               }
+       
+               GC.KeepAlive(obj);      // will keep alive 'obj' till this point
+
+        return returnValue;
+       }
+}
diff --git a/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivearray.csproj b/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivearray.csproj
new file mode 100644 (file)
index 0000000..a87917a
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="KeepAliveArray.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivedirectedgraph.cs b/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivedirectedgraph.cs
new file mode 100644 (file)
index 0000000..2f3784c
--- /dev/null
@@ -0,0 +1,272 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Build a Directed Graph with 100 nodes
+// Test KeepAlive for huge directed graphs
+
+namespace Default {
+
+using System;
+
+public class Graph
+{
+       private Vertex Vfirst = null;
+       private Vertex Vlast = null;
+       private Edge Efirst = null;
+       private Edge Elast = null;
+       private int WeightSum = 0;
+       
+       public static int Nodes;
+       public static bool flag;
+
+       public Graph(int n) { Nodes = n;}
+
+       public void SetWeightSum() {
+               Edge temp = Efirst;
+               WeightSum = 0;
+               while(temp != null) {
+                       WeightSum += temp.Weight;
+                       temp = temp.Next;
+               }
+       }
+       
+       public int GetWeightSum() {
+               return WeightSum;
+       }
+               
+       public void BuildEdge(int v1,int v2) {
+               Vertex n1 = null,n2 = null;
+               Vertex temp = Vfirst;
+               
+               while(temp != null) {
+            if (v1 == temp.Name)
+            {
+                               //found 1st node..
+                               n1 = temp;
+                               break;
+                       }
+                       else temp = temp.Next;
+               }
+               
+               //check if edge already exists
+               for(int i=0;i<n1.Num_Edges;i++) {
+            if (v2 == n1.Adjacent[i].Name)
+                return;
+               }
+
+               temp = Vfirst;
+               while(temp != null) {
+            if (v2 == temp.Name)
+            {
+                               //found 2nd node..
+                               n2 = temp;
+                               break;
+                       }
+                       else temp = temp.Next;
+               }
+               
+               n1.Adjacent[n1.Num_Edges++]=n2;
+               
+               Edge temp2 = new Edge(n1,n2);
+                       if(Efirst==null) {
+                               Efirst = temp2;
+                               Elast = temp2;
+                       }
+                       else {
+                               temp2.AddEdge(Elast,temp2);
+                               Elast = temp2;
+                       }
+       }
+       
+       public void BuildGraph() {
+               
+               // Build Nodes  
+               Console.WriteLine("Building Vertices...");
+               for(int i=0;i< Nodes; i++) {
+                       Vertex temp = new Vertex(i);
+                       if(Vfirst==null) {
+                            Vfirst = temp;
+                            Vlast = temp;
+                       }
+                       else {
+                            temp.AddVertex(Vlast,temp);
+                            Vlast = temp;
+                        }
+               }
+               
+               // Build Edges
+               Console.WriteLine("Building Edges...");
+       
+        Int32 seed = Environment.TickCount;
+               Random rand = new Random(seed);
+               
+               for(int i=0;i< Nodes;i++) {
+                   
+                   int j = rand.Next(0,Nodes);
+                   for(int k=0;k<j;k++) {
+                      int v2;
+                      while((v2 = rand.Next(0,Nodes))==i);     //select a random node, also avoid self-loops
+                      BuildEdge(i,v2);                //build edge betn node i and v2
+                     
+                      
+                   }           
+               }
+       }
+
+
+       public void CheckIfReachable() {
+               int[] temp = new int[Nodes];
+               Vertex t1 = Vfirst;
+               
+               Console.WriteLine("Making all vertices reachable...");
+               while(t1 != null) {
+                       for(int i=0;i<t1.Num_Edges;i++) {
+                               if(temp[t1.Adjacent[i].Name] == 0)
+                                       temp[t1.Adjacent[i].Name]=1;
+                       }
+                       t1 = t1.Next;
+               }
+
+               for(int v2=0;v2<Nodes;v2++) {
+                       if(temp[v2]==0) {  //this vertex is not connected
+                Int32 seed = Environment.TickCount;
+                               Random rand = new Random(seed);
+                               int v1;
+                               while((v1 = rand.Next(0,Nodes))==v2);     //select a random node, also avoid self-loops
+                               BuildEdge(v1,v2);
+                               temp[v2]=1;
+                       }
+               }
+               
+       }
+       
+
+       public void DeleteVertex() {
+
+               DeleteVertex(Vfirst);
+               
+       }
+
+       public void DeleteVertex(Vertex v) {
+               if(v == Vlast) {
+                       Vfirst=null;
+                       Vlast=null;
+                       GC.Collect();
+                       GC.WaitForPendingFinalizers();
+                       return;
+               }
+               Vertex temp = v.Next;
+               v=null;
+               GC.Collect();
+               GC.WaitForPendingFinalizers();
+               DeleteVertex(temp);
+               temp=null;
+               GC.Collect();
+               GC.WaitForPendingFinalizers();
+               
+       }
+
+       public Vertex ReturnVfirst() {
+               return(Vfirst);
+       }
+       
+}
+
+public class Vertex
+       {
+               public int Name;
+               //public bool Visited = false;
+               
+               public Vertex Next;
+               public Vertex[] Adjacent;
+               public Edge[] Edges;
+               public int Num_Edges = 0;
+               public static int count=0;
+
+               public Vertex(int val) {
+                       Name = val;
+                       Next = null;
+                       Adjacent = new Vertex[Graph.Nodes];     
+               }
+               
+               ~Vertex() {
+                       //Console.WriteLine("In Finalize of Vertex");
+                       count++;
+                       if((count==100) && (Graph.flag==false)) {
+                Test.exitCode = 1;
+                       }
+               }
+
+               public void AddVertex(Vertex x, Vertex y) {
+                       x.Next = y;                             
+               }
+               
+               public void DeleteAdjacentEntry(int n) {
+                       int temp=Num_Edges;
+                       for(int i=0;i< temp;i++) {
+                               if(n == Adjacent[i].Name) {
+                                       for(int j=i;j<Num_Edges;j++) 
+                                               Adjacent[j] = Adjacent[j+1];
+                                       Num_Edges--;
+                                       return;
+                               }
+                       }
+               }
+       }
+
+
+public class Edge 
+       {
+               public int Weight;
+               public Vertex v1,v2;
+               public Edge Next;
+       
+               public Edge(Vertex n1, Vertex n2) {
+                       v1=n1;
+                       v2=n2;
+                       
+                       int seed = n1.Name+n2.Name;
+                       Random rand = new Random(seed);
+                       Weight = rand.Next(0,50);
+               }
+               
+               public void AddEdge(Edge x, Edge y) {
+                       x.Next = y;                             
+               }
+
+       }
+
+
+public class Test
+{
+    public static int exitCode = 0;
+  public static int Main()
+  {
+       Graph.flag=false;
+    exitCode = 100;
+
+       Console.WriteLine("Test should pass with ExitCode 100");
+       Console.WriteLine("Building Graph with 100 vertices...");
+       Graph MyGraph = new Graph(100);  
+
+       MyGraph.BuildGraph();    
+       MyGraph.CheckIfReachable();
+
+       Console.WriteLine("Deleting all vertices...");
+
+       MyGraph.DeleteVertex();
+
+       GC.Collect();
+       GC.WaitForPendingFinalizers();
+
+       Vertex temp = MyGraph.ReturnVfirst();   
+       GC.KeepAlive(temp);     // will keep alive the graph till here
+
+       Console.WriteLine("Done...");
+       Graph.flag=true;        // to check if finalizers ran at shutdown or earlier
+    return exitCode;
+       
+  }
+}
+}
diff --git a/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivedirectedgraph.csproj b/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivedirectedgraph.csproj
new file mode 100644 (file)
index 0000000..a6f0c2a
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="KeepAliveDirectedGraph.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivefinalize.cs b/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivefinalize.cs
new file mode 100644 (file)
index 0000000..7c235b0
--- /dev/null
@@ -0,0 +1,54 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests KeepAlive() in Finalize
+
+using System;
+using System.Collections;
+
+public class Test {
+       
+       public class Dummy1 {
+               public static bool visited;
+               ~Dummy1() {
+                       Console.WriteLine("In Finalize() of Dummy1");
+                       Dummy2 temp = new Dummy2();
+                       visited=true;
+                       
+                       GC.Collect();
+                       GC.WaitForPendingFinalizers();
+                       GC.KeepAlive(temp);
+               }
+       }
+
+       public class Dummy2 {
+               public static bool visited;
+               ~Dummy2() {
+                       Console.WriteLine("In Finalize() of Dummy2");
+                       visited=true;
+               }
+       }
+
+       public static int Main() {
+
+        int returnValue = 0;
+               Dummy1 obj = new Dummy1();
+               
+               GC.Collect();
+               GC.WaitForPendingFinalizers();
+
+               if((Dummy1.visited == false) && (Dummy2.visited == false)) {  // has not visited the Finalize()
+            returnValue = 100;
+                       Console.WriteLine("Test passed!");
+               }
+               else {
+            returnValue = 1;
+                       Console.WriteLine("Test failed!");
+               }
+               
+               GC.KeepAlive(obj);
+
+        return returnValue;
+       }
+}
diff --git a/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivefinalize.csproj b/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivefinalize.csproj
new file mode 100644 (file)
index 0000000..590b4f6
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="KeepAliveFinalize.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivehandle.cs b/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivehandle.cs
new file mode 100644 (file)
index 0000000..7f4208f
--- /dev/null
@@ -0,0 +1,45 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests KeepAlive() with GCHandles
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Test {
+       public class Dummy {
+
+               public static bool visited;
+               ~Dummy() {
+                       //Console.WriteLine("In Finalize() of Dummy");
+                       visited=true;
+               }
+       }
+
+       public static int Main() {
+
+        int returnValue = 0;
+               Dummy obj = new Dummy();
+
+               Console.WriteLine("Allocating a Weak handle to object..");
+               GCHandle handle = GCHandle.Alloc(obj,GCHandleType.Weak);
+
+               GC.Collect();
+               GC.WaitForPendingFinalizers();
+               
+               if(Dummy.visited == false) {  // has not visited the Finalize()
+            returnValue = 100;
+                       Console.WriteLine("Test for KeepAlive() passed!");
+               }
+               else {
+            returnValue = 1;
+                       Console.WriteLine("Test for KeepAlive() failed!");
+               }
+
+               GC.KeepAlive(obj);      // will keep alive 'obj' till this point
+               GC.Collect();
+
+        return returnValue;
+       }
+}
diff --git a/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivehandle.csproj b/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivehandle.csproj
new file mode 100644 (file)
index 0000000..3197ab0
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="KeepAliveHandle.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivescope.cs b/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivescope.cs
new file mode 100644 (file)
index 0000000..7b041ff
--- /dev/null
@@ -0,0 +1,68 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests KeepAlive() scopes
+
+using System;
+
+public class Test {
+
+    public static int returnValue = 0;
+       public class Dummy {
+
+               public static bool visited;
+               ~Dummy() {
+                       //Console.WriteLine("In Finalize() of Dummy");  
+                       visited=true;
+               }
+       }
+
+       public class CreateObj {
+               public Dummy obj;
+               public bool result;
+
+               public CreateObj() {
+                       obj = new Dummy();
+                       result=false;
+               }
+               
+               public void RunTest() {
+                       GC.Collect();
+                       GC.WaitForPendingFinalizers();
+               
+                       
+                       if((Dummy.visited == false)) {  // has not visited the Finalize() yet
+                               result=true;
+                       }
+               
+                       GC.KeepAlive(obj);      // will keep alive 'obj' till this point
+               
+                       obj=null;
+                       GC.Collect();
+                       GC.WaitForPendingFinalizers();
+               
+                       if(result==true && Dummy.visited==true)
+                returnValue = 100;
+                       else
+                returnValue = 1;
+               }
+
+       }
+
+       public static int Main() {
+
+               CreateObj temp = new CreateObj();
+               temp.RunTest();
+
+        if (returnValue == 100) 
+                       Console.WriteLine("Test passed!");              
+               else
+                       Console.WriteLine("Test failed!");
+
+        return returnValue;
+       }
+}
+
+
+
diff --git a/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivescope.csproj b/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivescope.csproj
new file mode 100644 (file)
index 0000000..a1281ab
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="KeepAliveScope.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivetry.cs b/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivetry.cs
new file mode 100644 (file)
index 0000000..2115c29
--- /dev/null
@@ -0,0 +1,60 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests KeepAlive() in try...catch...finally
+
+using System;
+
+public class Test
+{
+
+    public class Dummy
+    {
+
+        public static bool visited;
+        ~Dummy()
+        {
+            //Console.WriteLine("In Finalize() of Dummy");
+            visited=true;
+        }
+    }
+
+    public static int Main()
+    {
+
+        Dummy[] obj = new Dummy[100];
+
+        try
+        {
+            for(int i=0;i<100;i++)
+            {
+                obj[i]= new Dummy();
+            }
+            throw new IndexOutOfRangeException();
+        }
+        catch(Exception)
+        {
+            Console.WriteLine("Caught exception");
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+        }
+        finally
+        {
+            Console.WriteLine("Should come here..still keeping object alive");
+            GC.KeepAlive(obj);
+        }
+
+        if(Dummy.visited == false)
+        {  // has not visited the Finalize()
+            Console.WriteLine("Test for KeepAlive() passed!");
+            return 100;
+        }
+        else
+        {
+            Console.WriteLine("Test for KeepAlive() failed!");
+            return 1;
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivetry.csproj b/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivetry.csproj
new file mode 100644 (file)
index 0000000..4681c8b
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="KeepAliveTry.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivetypes.cs b/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivetypes.cs
new file mode 100644 (file)
index 0000000..80189ae
--- /dev/null
@@ -0,0 +1,70 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Tests KeepAlive() with different types of inputs
+
+using System;
+
+public class Test {
+
+       public class Dummy {
+
+               public static bool visited;
+               ~Dummy() {
+                       //Console.WriteLine("In Finalize() of Dummy");  
+                       visited=true;
+               }
+       }
+
+       public struct StrDummy {
+               public int val;
+               public static bool flag;
+
+               public StrDummy(int v) {
+                       val=v;
+                       flag=true;
+               }
+       }
+
+       public enum Color
+       {
+               Red, Blue, Green
+       }
+
+       public static int  Main() {
+
+        int returnValue = 0;
+               Dummy obj = new Dummy();
+               StrDummy strobj = new StrDummy(999);
+               Color enumobj = new Color();
+       
+               GC.Collect();
+               GC.WaitForPendingFinalizers();
+               
+                       
+               if((Dummy.visited == false) && (StrDummy.flag==true)) {  // has not visited the Finalize()
+            returnValue = 100;
+                       Console.WriteLine("Test passed!");
+               }
+               else {
+            returnValue = 1;
+                       Console.WriteLine("Test failed!");
+               }
+
+               GC.KeepAlive(obj);      // will keep alive 'obj' till this point
+               GC.KeepAlive(1000000);
+               GC.KeepAlive("long string for testing");
+               GC.KeepAlive(-12345678);
+               GC.KeepAlive(3456.8989);
+               GC.KeepAlive(true);
+               GC.KeepAlive(strobj);
+               GC.KeepAlive(enumobj);
+
+        return returnValue;
+               
+       }
+}
+
+
+
diff --git a/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivetypes.csproj b/src/coreclr/tests/src/GC/Features/KeepAlive/keepaliveother/keepalivetypes.csproj
new file mode 100644 (file)
index 0000000..aca672b
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="KeepAliveTypes.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/LOHCompaction/app.config b/src/coreclr/tests/src/GC/Features/LOHCompaction/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompact_stress.cs b/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompact_stress.cs
new file mode 100644 (file)
index 0000000..52e1561
--- /dev/null
@@ -0,0 +1,189 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Diagnostics;
+using System.Threading;
+using System.Runtime;
+
+//This test creates high fragmentation in the large object heap 
+//LOH fragmentation: up to 80-90%
+//No large objects pinned
+//Max GC heap size = 137MB with default param (100 iterations, 4 threads)
+//Code is from test ConcurrentSpin2 and LOH compaction is added
+class PriorityTest
+{
+    private byte[][] old;
+    private byte[][] med;
+    private Random rand;
+
+    private int oldDataSize;
+    private int medDataSize;
+    private int iterCount;
+    private int meanAllocSize;
+    private int medTime;
+    private int youngTime;
+
+
+    public PriorityTest(int oldDataSize, int medDataSize,
+                        int iterCount, int meanAllocSize,
+                        int medTime, int youngTime)
+    {
+        rand = new Random(314159);
+        this.oldDataSize = oldDataSize;
+        this.medDataSize = medDataSize;
+        this.iterCount = iterCount;
+        this.meanAllocSize = meanAllocSize;
+        this.medTime = medTime;
+        this.youngTime = youngTime;
+    }
+
+    // creates initial arrays
+    void AllocTest(int oldDataSize, int medDataSize, int meanAllocSize)
+    {
+        old = new byte[oldDataSize][];
+        med = new byte[medDataSize][];
+
+        for (int i = 0; i < old.Length; i++)
+        {
+            old[i] = new byte[meanAllocSize];
+        }
+
+        for (int i = 0; i < med.Length; i++)
+        {
+            med[i] = new byte[meanAllocSize];
+        }
+    }
+
+    // churns data in the heap by replacing byte arrays with new ones
+    void SteadyState(int oldDataSize, int medDataSize,
+                        int iterCount, int meanAllocSize,
+                        int medTime, int youngTime)
+    {
+
+        for (int i = 0; i < iterCount; i++)
+        {
+            byte[] newarray = new byte[meanAllocSize];
+
+            if ((i % medTime) == 0)
+            {
+                old[rand.Next(0, old.Length)] = newarray;
+            }
+            if ((i % youngTime) == 0)
+            {
+                med[rand.Next(0, med.Length)] = newarray;
+            }
+            if ((i % 500) == 0) 
+            {
+                Thread.Sleep(10);
+            }
+            if ((i % (1000 * System.Threading.Thread.CurrentThread.ManagedThreadId)) == 0)
+            {
+                GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
+                if ((i % 5 == 0) && (System.Runtime.GCSettings.LatencyMode != System.Runtime.GCLatencyMode.Batch))
+                    GC.Collect();
+            }
+        }
+    }
+
+    // method that runs the test
+    public void RunTest()
+    {
+        for (int iteration = 0; iteration < iterCount; iteration++)
+        {
+            AllocTest(oldDataSize, medDataSize, meanAllocSize);
+
+            SteadyState(oldDataSize, medDataSize,
+                iterCount, meanAllocSize,
+                medTime, youngTime);
+
+            if (((iteration + 1) % 20) == 0)
+                Console.WriteLine("Thread: {1} Finished iteration {0}", iteration, System.Threading.Thread.CurrentThread.Name);
+        }
+
+    }
+
+}
+
+
+class ConcurrentRepro
+{
+
+    public static void Usage()
+    {
+        Console.WriteLine("Usage:");
+        Console.WriteLine("\t<num iterations> <num threads>");
+    }
+
+    public static int[] ParseArgs(string[] args)
+    {
+        int[] parameters = new int[2];
+
+        // set defaults
+        parameters[0] = 100;
+        parameters[1] = 4;
+
+        if (args.Length == 0)
+        {
+            //use defaults
+            Console.WriteLine("Using defaults: 100 iterations, 4 threads");
+            return parameters;
+        }
+        if (args.Length == parameters.Length)
+        {
+            for (int i = 0; i < args.Length; i++)
+            {
+                int j = 0;
+                if (!int.TryParse(args[i], out j))
+                {
+                    Usage();
+                    return null;
+                }
+                parameters[i] = j;
+            }
+
+            return parameters;
+        }
+
+        // incorrect number of arguments        
+        Usage();
+        return null;
+    }
+
+
+    public static int Main(string[] args)
+    {
+
+        // parse arguments
+        int[] parameters = ParseArgs(args);
+        if (parameters == null)
+        {
+            return 0;
+        }
+
+
+
+        PriorityTest priorityTest = new PriorityTest(1000000, 5000, parameters[0], 17, 30, 3);
+        ThreadStart startDelegate = new ThreadStart(priorityTest.RunTest);
+
+        // create threads
+        Thread[] threads = new Thread[parameters[1]];
+        for (int i = 0; i < threads.Length; i++)
+        {
+            threads[i] = new Thread(startDelegate);
+            threads[i].Name = String.Format("Thread{0}", i);
+            threads[i].Start();
+        }
+
+        // wait for threads to complete
+        for (int i = 0; i < threads.Length; i++)
+        {
+            threads[i].Join();
+        }
+
+        return 100;
+    }
+}
+
+
diff --git a/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompact_stress.csproj b/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompact_stress.csproj
new file mode 100644 (file)
index 0000000..f3adce1
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="LOHCompact_Stress.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi.cs b/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi.cs
new file mode 100644 (file)
index 0000000..fc69b41
--- /dev/null
@@ -0,0 +1,137 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Runtime;
+using System.Reflection;
+
+
+namespace LOHCompactAPI
+{
+    class Program
+    {
+        static int ListSize = 500;
+        static List<byte[]> shortLivedList = new List<byte[]>(ListSize);
+        static List<byte[]> LongLivedList = new List<byte[]>(ListSize);
+
+        public static int Main(string[] args)
+        {
+            int retVal=0;
+            for (int i = 0; i < 3; i++)
+            {
+                retVal = Runtest(i);
+                Console.WriteLine("Heap size=" + GC.GetTotalMemory(false));
+                if (retVal != 100)
+                    break;
+            }
+            if (retVal == 100)
+            Console.WriteLine("Test passed");
+            return retVal;
+        }
+
+        static int Runtest(int count)
+        {
+            //Create fragmentation in the Large Object Heap
+            System.Random rnd = new Random(12345);
+            for (int i = 0; i < ListSize; i++)
+            {
+                shortLivedList.Add(new byte[rnd.Next(85001, 100000)]);
+                LongLivedList.Add(new byte[rnd.Next(85001, 100000)]);
+
+            }
+            shortLivedList.Clear();
+            GC.Collect();  //when using perfview, LOH should be fragmented after this GC
+
+            //Verify the initial compaction mode should be default
+            if (GCSettings.LargeObjectHeapCompactionMode != GCLargeObjectHeapCompactionMode.Default)
+            {
+                Console.WriteLine("Initial GCLargeObjectHeapCompactionMode should be default; instead it is " + GCSettings.LargeObjectHeapCompactionMode);
+                return 1;
+            }
+            //Set the compaction mode to compact the large object heap
+            int initial_collectionCount = GetBlockingGen2Count();
+            GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
+
+            //verify the compaction mode is set correctly
+            if (GCSettings.LargeObjectHeapCompactionMode != GCLargeObjectHeapCompactionMode.CompactOnce)
+            {
+                Console.WriteLine("GCLargeObjectHeapCompactionMode should be CompactOnce; instead it is " + GCSettings.LargeObjectHeapCompactionMode);
+                return 2;
+            }
+
+            //CompactionMode should revert to default after a compaction has happened
+
+            //The following byte array allocation has the purpose to try to trigger a blocking Gen2 collection. LOH should be compacted during the next blocking Gen2 GC.
+            byte[] bArr;
+            int listSize2 = 1000;
+            List<byte[]> newList = new List<byte[]>();
+            List<byte[]> tempList = new List<byte[]>();
+            bool Gen2Happened = false;
+            
+            for (int k = 0; !Gen2Happened && (k < listSize2); k++)
+            {
+                newList.Add(new byte[rnd.Next(20, 5000)]);
+                for (int i = 0; i < ListSize; i++)
+                {
+                    bArr = new byte[rnd.Next(20, 5000)];
+                    tempList.Add(new byte[rnd.Next(20, 5000)]);
+
+                    if (GetBlockingGen2Count() > initial_collectionCount)
+                    {
+                        Gen2Happened = true;
+                        Console.WriteLine("Blocking Gen2 collection happened");
+                        //when using perfview,LOH fragmentation should be zero after this GC
+                        break;
+                    }
+                   
+                }
+
+                if(k>=10)
+                {
+                    newList[rnd.Next(0, newList.Count)] = new byte[rnd.Next(20, 5000)];
+                    newList[rnd.Next(0, newList.Count)] = new byte[rnd.Next(20, 5000)];
+                }
+                if(k%10==0)
+                    tempList.Clear();
+          
+                    
+             }
+            if (GetBlockingGen2Count() == initial_collectionCount) //a blocking Gen2 collection did not happen; trigger one.
+                GC.Collect();
+
+            if (GCSettings.LargeObjectHeapCompactionMode != GCLargeObjectHeapCompactionMode.Default)
+            {
+                Console.WriteLine("GCLargeObjectHeapCompactionMode should revert to default after compaction happened; instead it is " + GCSettings.LargeObjectHeapCompactionMode);
+                return 3;
+            }
+
+            Console.WriteLine("Run " + count + " passed");
+            return 100;
+        }
+
+        //Only count the blocking gen2 GC's. Concurrent GC's should be subtracted from the total GC count.
+        public static int GetBlockingGen2Count()
+        {
+            //Get the number of concurrent collections (can use this method only through reflection):
+            MethodInfo collectionCountmethod = null;
+            Type GCType = Type.GetType("System.GC");
+            foreach(MethodInfo m in GCType.GetMethods(BindingFlags.Static | BindingFlags.NonPublic))
+            {
+                if (m.Name.Equals("_CollectionCount") && m.GetParameters().Length == 2) collectionCountmethod = m;
+            }
+            if (collectionCountmethod == null)
+            {
+                Console.WriteLine("collectionCount method is null");
+                return 0;
+            }
+            object[] parameters = new object[2];
+            parameters[0] = 2;
+            parameters[1] = 1; // special gc count
+            int backgroundCollections = (int)collectionCountmethod.Invoke(null, parameters);
+
+            return (GC.CollectionCount(2) - backgroundCollections);
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi.csproj b/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi.csproj
new file mode 100644 (file)
index 0000000..55a2975
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="LOHCompactAPI.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi2.cs b/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi2.cs
new file mode 100644 (file)
index 0000000..e25baad
--- /dev/null
@@ -0,0 +1,218 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Runtime;
+using System.Reflection;
+using System.Threading;
+
+
+namespace LOHCompactAPI
+{
+    class Program
+    {
+        static int ListSize = 500;
+        static List<byte[]> shortLivedList = new List<byte[]>(ListSize);
+        static List<byte[]> LongLivedList = new List<byte[]>(ListSize);
+        static volatile bool testDone = false;
+
+        //There are several threads that allocate, and the main thread calls the compacting API
+        //Verify that the compaction mode changes to default after a blocking GC happened, and does not change if a blocking GC did not happen.
+        public static int Main(string[] args)
+        {
+            int retVal = 100;
+            int iterations = 10;
+
+            if (args.Length > 0)
+                iterations = Int32.Parse(args[0]);
+            Console.WriteLine("Running {0} iterations", iterations);
+
+            testDone = false;
+
+            Thread AllocatingThread = new Thread(Allocate);
+            AllocatingThread.Start();
+            int numThreads = 100;
+            Thread[] threadArr = new Thread[numThreads];
+            for (int i = 0; i < numThreads; i++)
+            {
+                threadArr[i] = new Thread(AllocateTempObjects);
+                threadArr[i].Start();
+            }
+
+            for (int i = 0; i < iterations; i++)
+            {
+                if (!Test1())
+                {
+                    retVal = 1;
+                    break;
+                }
+                Thread.Sleep(3);
+            }
+            Console.WriteLine("Test1 passed");
+
+            for (int i = 0; i < iterations; i++)
+            {
+                if (!Test2())
+                {
+                    retVal = 1;
+                    break;
+                }
+                Thread.Sleep(100);
+            }
+            Console.WriteLine("Test2 passed");
+
+
+            testDone = true;
+            AllocatingThread.Join();
+            for (int i = 0; i < numThreads; i++)
+            {
+                threadArr[i].Join();
+            }
+            return retVal;
+        }
+
+        public static bool Test1()
+        {
+
+
+            Console.WriteLine("Setting GCLargeObjectHeapCompactionMode.CompactOnce");
+            int GCCount = 0;
+            int initialGCCount = GetBlockingGen2Count();
+            GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
+            GCCount = GetBlockingGen2Count();
+            if (initialGCCount != GCCount)
+            {
+                Console.WriteLine("A GC happened while setting CompactOnce. Old count {0}, new Count {1}", initialGCCount, GCCount);
+                //skip this run
+                return true;
+            }
+
+
+            Thread.Sleep(100);
+            int currentGCCount = GetBlockingGen2Count();
+            GCLargeObjectHeapCompactionMode mode = GCSettings.LargeObjectHeapCompactionMode;
+            GCCount = GetBlockingGen2Count();
+            if (currentGCCount != GCCount)  //a GC happened in between these calls
+            {
+                Console.WriteLine("A GC happened while getting Compaction Mode. Old count {0}, new Count {1}", currentGCCount, GCCount);
+                //skip this run
+                return true;
+            }
+
+            Console.WriteLine("initial GC count: {0}; currentGCCount: {1}", initialGCCount, currentGCCount);
+            Console.WriteLine(mode);
+            if (currentGCCount == initialGCCount)
+            {
+                if (mode != GCLargeObjectHeapCompactionMode.CompactOnce)
+                {
+                    Console.WriteLine("GCLargeObjectHeapCompactionMode should be CompactOnce; instead it is " + mode);
+                    return false;
+                }
+            }
+            else
+            {
+                if (mode != GCLargeObjectHeapCompactionMode.Default)
+                {
+                    Console.WriteLine("GCLargeObjectHeapCompactionMode should be Default; instead it is " + mode);
+                    return false;
+                }
+            }
+            return true;
+
+        }
+
+        public static bool Test2()
+        {
+
+
+            Console.WriteLine("Setting GCLargeObjectHeapCompactionMode.CompactOnce");
+            GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
+            GC.Collect();
+            GCLargeObjectHeapCompactionMode mode = GCSettings.LargeObjectHeapCompactionMode;
+            Console.WriteLine(mode);
+            if (mode != GCLargeObjectHeapCompactionMode.Default)
+            {
+                Console.WriteLine("GCLargeObjectHeapCompactionMode should be CompactOnce; instead it is " + mode);
+                return false;
+            }
+
+            return true;
+        }
+
+        public static void AllocateTempObjects(object threadInfoObj)
+        {
+            int listSize2 = 1000;
+            List<byte[]> tempList = new List<byte[]>();
+            while (!testDone)
+            {
+                byte[] temp = new byte[20];
+                for (int i = 0; i < listSize2; i++)
+                {
+                    tempList.Add(new byte[50]);
+                }
+                tempList.Clear();
+            }
+
+        }
+
+        public static void Allocate(object threadInfoObj)
+        {
+            int ListSize = 300;
+            System.Random rnd = new Random(1122);
+
+            int listSize2 = 1000;
+            List<byte[]> newList = new List<byte[]>(500 + 1000);
+
+
+            while (!testDone)
+            {
+                for (int i = 0; i < ListSize; i++)
+                {
+                    newList.Add(new byte[85000]);
+                    newList.Add(new byte[200]);
+                    Thread.Sleep(10);
+                }
+                for (int i = 0; i < listSize2; i++)
+                {
+                    newList.Add(new byte[50]);
+                }
+                newList.Clear();
+            }
+        }
+
+
+
+
+        //Only count the blocking gen2 GC's. Concurrent GC's should be subtracted from the total GC count.
+        public static int GetBlockingGen2Count()
+        {
+
+            //Get the number of concurrent collections (can use this method only through reflection):
+            MethodInfo collectionCountmethod = null;
+            Type GCType = Type.GetType("System.GC");
+            foreach(MethodInfo m in GCType.GetMethods(BindingFlags.Static | BindingFlags.NonPublic))
+            {
+                if (m.Name.Equals("_CollectionCount") && m.GetParameters().Length == 2) collectionCountmethod = m;
+            }
+            if (collectionCountmethod == null)
+            {
+                Console.WriteLine("collectionCount method is null");
+                return 0;
+            }
+            if (collectionCountmethod == null)
+            {
+                Console.WriteLine("collectionCount method is null");
+                return 0;
+            }
+            object[] parameters = new object[2];
+            parameters[0] = 2;
+            parameters[1] = 1; // special gc count
+            int backgroundCollections = (int)collectionCountmethod.Invoke(null, parameters);
+            int TotalCollections = GC.CollectionCount(2);
+            Console.WriteLine("Total collections {0}, background {1}", TotalCollections, backgroundCollections);
+            return (TotalCollections - backgroundCollections);
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi2.csproj b/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi2.csproj
new file mode 100644 (file)
index 0000000..a360930
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="LOHCompactAPI2.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi_exceptions.cs b/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi_exceptions.cs
new file mode 100644 (file)
index 0000000..0ba7c29
--- /dev/null
@@ -0,0 +1,63 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime;
+
+
+
+namespace LOHCompactAPI
+{
+    class Program
+    {
+
+        public static int Main(string[] args)
+        {
+            for(int i = 0; i <= 5; i++)
+            {
+                Console.WriteLine(i);
+                if ((GCLargeObjectHeapCompactionMode)(i) == GCLargeObjectHeapCompactionMode.Default)
+                {
+                    Console.WriteLine("Default");
+                    continue;
+                }
+                if ((GCLargeObjectHeapCompactionMode)(i) == GCLargeObjectHeapCompactionMode.CompactOnce)
+                {
+                    Console.WriteLine("CompactOnce");
+                    continue;
+                }
+
+                bool exc = false;
+                try
+                {
+                    GCSettings.LargeObjectHeapCompactionMode = (GCLargeObjectHeapCompactionMode)(i);
+                }
+                catch (System.ArgumentOutOfRangeException e1)
+                {
+                    Console.WriteLine("Caught expected exception " + e1);
+                    exc = true;
+                }
+                catch (System.Exception e2)
+                {
+                    Console.WriteLine("Wrong type of exception " + e2);
+                    Console.WriteLine("Expected ArgumentOutOfrangeException");
+                    return 1;
+                }
+
+                if (!exc)
+                {
+                    Console.WriteLine("Expected ArgumentOutOfrangeException for out of range input for LargeObjectHeapCompactionMode");
+                    return 2;
+                }
+            }
+           
+            Console.WriteLine("Test passed");
+            return 100;
+        }
+
+
+    }
+}
+
+
diff --git a/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi_exceptions.csproj b/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactapi_exceptions.csproj
new file mode 100644 (file)
index 0000000..2e4d710
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="LOHCompactAPI_Exceptions.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactscenariorepro.cs b/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactscenariorepro.cs
new file mode 100644 (file)
index 0000000..23b3c84
--- /dev/null
@@ -0,0 +1,132 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Runtime;
+using System.Reflection;
+using System.Threading;
+//Repro for bug Bug 656705: Heap corruption when using LOH compaction
+
+
+namespace LOHCompactScenarioRepro
+{
+    public class Program
+    {
+        static int ListSize = 500;
+        static List<byte[]> shortLivedList = new List<byte[]>(ListSize);
+        static List<byte[]> LongLivedList = new List<byte[]>(ListSize);
+        static volatile bool testDone = false;
+
+        //There are several threads that allocate, and the main thread calls the compacting API
+        public static int Main(string[] args)
+        {
+            int minutesTorRun = 10;
+
+            if (args.Length > 0)
+                minutesTorRun = Int32.Parse(args[0]);
+            Console.WriteLine("Running {0} minutes", minutesTorRun);
+
+            testDone = false;
+
+            Thread AllocatingThread = new Thread(Allocate);
+            AllocatingThread.Start();
+            int numThreads = 100;
+            Thread[] threadArr = new Thread[numThreads];
+            for (int i = 0; i < numThreads; i++)
+            {
+                threadArr[i] = new Thread(AllocateTempObjects);
+                threadArr[i].Start();
+            }
+            System.Diagnostics.Stopwatch stw = System.Diagnostics.Stopwatch.StartNew();
+
+            int iter = 0;
+            while (true)
+            {
+               GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
+                GC.Collect();
+
+                for (int i = 0; i < 100; i++)
+                {
+                    System.Threading.Thread.Sleep(80);
+                    GC.Collect();
+                }
+                iter++;
+                if (stw.ElapsedMilliseconds > minutesTorRun * 60 * 1000)
+                {
+                    Console.WriteLine("Time exceeded {0} min", minutesTorRun);
+                    Console.WriteLine("Ran {0} iterations", iter);
+                    break;
+                }
+            }
+
+
+            testDone = true;
+            AllocatingThread.Join();
+            for (int i = 0; i < numThreads; i++)
+            {
+                threadArr[i].Join();
+            }
+
+            if (iter < 3)
+            {
+                Console.WriteLine("Test needs to run at least a few iterations in order to be useful.");
+                return 5;
+            }
+            return 100;
+        }
+
+      
+
+        public static void AllocateTempObjects(object threadInfoObj)
+        {
+            int listSize2 = 1000;
+            List<byte[]> tempList = new List<byte[]>();
+            while (!testDone)
+            {
+                byte[] temp = new byte[20];
+                for (int i = 0; i < listSize2; i++)
+                {
+                    if (i % 200 == 0)
+                    {
+                        tempList.Add(new byte[85000]);
+                    }
+                    else
+                    {
+                        tempList.Add(new byte[50]);
+                    }
+                   
+                }
+                tempList.Clear();
+            }
+
+        }
+
+        public static void Allocate(object threadInfoObj)
+        {
+            int ListSize = 300;
+            System.Random rnd = new Random(1122);
+
+            int listSize2 = 1000;
+            List<byte[]> newList = new List<byte[]>(500 + 1000);
+
+
+            while (!testDone)
+            {
+                for (int i = 0; i < ListSize; i++)
+                {
+                    newList.Add(new byte[85000]);
+                    newList.Add(new byte[200]);
+                    Thread.Sleep(10);
+                }
+                for (int i = 0; i < listSize2; i++)
+                {
+                    newList.Add(new byte[50]);
+                }
+                newList.Clear();
+            }
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactscenariorepro.csproj b/src/coreclr/tests/src/GC/Features/LOHCompaction/lohcompactscenariorepro.csproj
new file mode 100644 (file)
index 0000000..e4962bb
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="LOHCompactScenarioRepro.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/LOHCompaction/lohpin.cs b/src/coreclr/tests/src/GC/Features/LOHCompaction/lohpin.cs
new file mode 100644 (file)
index 0000000..8a91fb2
--- /dev/null
@@ -0,0 +1,114 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Runtime.InteropServices;
+using System.Runtime;
+
+namespace LOHPin
+{
+    class LOHPin
+    {
+        //Pin an object on the Large Object Heap and verify it does not move during a LOH compaction
+        //Also verify that most of the large objects not pinned have moved
+
+        /* What the test does:
+         *   - create high fragmentation in the LOH
+         *   - pin some of the large objects
+         *   - compact LOH then check the address of the objects
+         * */
+        static int Main(string[] args)
+        {
+            List<GCHandle> GCHandleList = new List<GCHandle>();
+            int ListSize = 300;
+            List<byte[]> shortLivedList = new List<byte[]>(ListSize);
+            List<byte[]> LongLivedList = new List<byte[]>(ListSize-ListSize/10);
+             List<IntPtr> LongLivedAddress = new List<IntPtr>(ListSize-ListSize/10);  //addresses of objects in LongLivedList
+            List<byte[]> PinList = new List<byte[]>(ListSize/10);
+            List<IntPtr> PinAddress = new List<IntPtr>(ListSize/10); //addresses of objects in PinList
+            //Create fragmentation in the Large Object Heap
+            System.Random rnd = new Random(12345);
+            for (int i = 0; i < ListSize; i++)
+            {
+                shortLivedList.Add(new byte[rnd.Next(85001, 100000)]);
+
+                byte[] bt = new byte[rnd.Next(85001, 100000)];
+                if (i % 10 == 0)  //object pinned
+                {
+                    PinList.Add(bt);
+                    GCHandle gch = GCHandle.Alloc(bt,GCHandleType.Pinned);
+                    GCHandleList.Add(gch);
+                    PinAddress.Add(gch.AddrOfPinnedObject());
+
+                }
+                else  //object not pinned
+                {
+                    LongLivedList.Add(bt);
+                    GCHandle gch = GCHandle.Alloc(bt, GCHandleType.Pinned);
+                    LongLivedAddress.Add(gch.AddrOfPinnedObject());
+                    gch.Free();
+                }
+
+            }
+            shortLivedList.Clear();
+            GC.Collect();  //LOH should be fragmented 40-50% after this GC - can observe this with perfview
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+
+           GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
+            GC.Collect();
+        
+
+            //check the addresses of objects; pinned and not pinned
+            Console.WriteLine("Check the pinned list");
+            for (int i = 0; i < PinList.Count; i++)
+            {
+                GCHandle gch = GCHandle.Alloc(PinList[i], GCHandleType.Pinned);
+                IntPtr newAddress = gch.AddrOfPinnedObject();
+                Console.WriteLine("OldAddress={0}, NewAddress={1}", PinAddress[i], newAddress);
+                gch.Free();
+                if (!(PinAddress[i] == newAddress))
+                {
+                    Console.WriteLine("OldAddress={0}, NewAddress={1}", PinAddress[i], newAddress);
+                    Console.WriteLine("Test failed");
+                    return 2;
+                }
+            }
+
+            int moved = 0;
+            Console.WriteLine("Check the non pinned list");
+            for (int i = 0; i < LongLivedList.Count; i++)
+            {
+                GCHandle gch = GCHandle.Alloc(LongLivedList[i], GCHandleType.Pinned);
+                IntPtr newAddress = gch.AddrOfPinnedObject();
+                Console.WriteLine("OldAddress={0}, NewAddress={1}", LongLivedAddress[i], newAddress);
+                gch.Free();
+                if (!(LongLivedAddress[i] == newAddress))
+                {
+                    moved++;
+                }
+            }
+            Console.WriteLine(moved + " objects have moved out of " + LongLivedList.Count);
+            if (moved < LongLivedList.Count/2)
+            {
+                Console.WriteLine("Test failed. Too few objects have moved during compaction");
+                return 2;
+            }
+
+            Console.WriteLine("Test passed");
+            return 100;
+         
+        }
+
+      
+      
+    }
+
+   
+}
diff --git a/src/coreclr/tests/src/GC/Features/LOHCompaction/lohpin.csproj b/src/coreclr/tests/src/GC/Features/LOHCompaction/lohpin.csproj
new file mode 100644 (file)
index 0000000..43d99c5
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="LOHPin.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/LOHFragmentation/app.config b/src/coreclr/tests/src/GC/Features/LOHFragmentation/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Features/LOHFragmentation/lohfragmentation.cs b/src/coreclr/tests/src/GC/Features/LOHFragmentation/lohfragmentation.cs
new file mode 100644 (file)
index 0000000..2c060dc
--- /dev/null
@@ -0,0 +1,143 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+using System.Collections.Generic;
+
+//Repro from http://www.simple-talk.com/dotnet/.net-framework/the-dangers-of-the-large-object-heap/
+
+
+
+
+namespace LOH_test
+{
+
+    class Program
+    {
+        //percent difference between the bytes allocated with small blocks only and with larger blocks
+        //This accounts for difference in fragmentation
+        const int maxDiffPercent = 30;
+
+        // Static variable used to store our 'big' block. This ensures that the block is always up for garbage collection.
+
+        static byte[] bigBlock;
+
+
+        // Allocates 90,000 byte blocks, optionally intersperced with larger blocks
+        // Return how many MB can be allocated until OOM
+        static int Fill(bool allocateBigBlocks)
+        {
+
+            // Number of bytes in a small block
+
+            // 90000 bytes, just above the limit for the LOH
+
+            const int blockSize = 90000;
+
+
+
+            // Number of bytes in a larger block: 16Mb initially
+
+            int largeBlockSize = 1 << 24;
+
+
+
+            // Number of small blocks allocated
+
+            int count = 0;
+
+
+
+            try
+            {
+
+                // We keep the 'small' blocks around 
+
+                // (imagine an algorithm that allocates memory in chunks)
+
+                List<byte[]> smallBlocks = new List<byte[]>();
+
+
+
+                for (; ; )
+                {
+
+                    // Allocate a temporary larger block if we're set up to do so
+
+                    if (allocateBigBlocks)
+                    {
+
+                        bigBlock = new byte[largeBlockSize];
+
+                        // The next 'large' block will be just slightly larger
+
+                        largeBlockSize++;
+
+                    }
+
+
+
+                    // Allocate a small block
+
+                    smallBlocks.Add(new byte[blockSize]);
+
+                    count++;
+
+                }
+
+            }
+
+            catch (OutOfMemoryException)
+            {
+
+                // Force a GC, which should empty the LOH again
+
+                bigBlock = null;
+
+                GC.Collect();
+
+            }
+
+            int TotalMBAllocated = (int)((double)(count * blockSize) / (double)(1024 * 1024));
+
+            // Display the results for the amount of memory we managed to allocate
+
+            Console.WriteLine("{0}: {1}Mb allocated"
+
+                              , (allocateBigBlocks ? "With large blocks" : "Only small blocks")
+                              , TotalMBAllocated);
+
+            return TotalMBAllocated;
+
+        }
+
+
+
+        static int Main(string[] args)
+        {
+
+            // Display results for cases both with and without the larger blocks
+
+            int w_LargerBlocks = Fill(true);
+
+            int onlySmallBlocks = Fill(false);
+
+            int FragmentationDiffPercent = (int) (((double)(onlySmallBlocks - w_LargerBlocks) / (double)onlySmallBlocks) * 100);
+            Console.WriteLine("Fragmentation difference percent = {0}%", FragmentationDiffPercent);
+            
+
+            if (FragmentationDiffPercent > maxDiffPercent)
+            {
+                Console.WriteLine("Test Failed!");
+                return 1;
+            }
+            Console.WriteLine("Test Passed");
+            return 100;
+
+        }
+
+    }
+
+}
diff --git a/src/coreclr/tests/src/GC/Features/LOHFragmentation/lohfragmentation.csproj b/src/coreclr/tests/src/GC/Features/LOHFragmentation/lohfragmentation.csproj
new file mode 100644 (file)
index 0000000..c1d0206
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="LOHFragmentation.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/PartialCompaction/app.config b/src/coreclr/tests/src/GC/Features/PartialCompaction/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Features/PartialCompaction/eco1.cs b/src/coreclr/tests/src/GC/Features/PartialCompaction/eco1.cs
new file mode 100644 (file)
index 0000000..522c2ec
--- /dev/null
@@ -0,0 +1,820 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Runtime.InteropServices;
+
+//Test for Partial Compaction
+//Goals: create fragmentation in Gen2
+//Allocation should not be too intense
+//For testing the concurrent phase of partial compaction: update references between objects
+//What the test does:
+// 1.Allocating phase: 
+//-Allocate n regions
+//-When objects get in Gen2 release the objects used to create spaces
+//-Create refs from objects in these regions to ephemeral objects
+// 2.Steady state 
+//- randomly change references between objects
+//- release some of the existing objects (to create fragmentation in the existing regions)
+// Repeat from 1.
+namespace PartialCompactionTest
+{
+    public class PartialCompactionTest
+    {
+
+        //Define the size buckets:
+        public struct SizeBucket
+        {
+            public int minsize;
+            public int maxsize;
+            //public float percentage;  //percentage of objects that fall into this bucket
+            public SizeBucket(int min, int max)
+            {
+                //
+                minsize = min;
+                maxsize = max;
+            }
+
+        }
+
+        //Buckets are defined as following:
+        //Bucket1: 17 bytes to 200 bytes
+        //Bucket2: 200bytes to 1000 bytes
+        //Bucket3: 1000 bytes to 10000 bytes
+        //Bucket4: 10000 bytes to 80000 bytes
+        //The rest is over 85000 bytes (Large Object Heap)
+        private const int SIZEBUCKET_COUNT = 4;
+        private const int BUCKET1_MIN = 50;
+        private const int BUCKET2_MIN = 200;
+        private const int BUCKET3_MIN = 1000;
+        private const int BUCKET4_MIN = 10000;
+        private const int BUCKETS_MAX = 80000;
+        //////
+
+        public const int DEFAULT_ITERATIONS = 100;
+        public static int countIters = DEFAULT_ITERATIONS;
+        public static long timeout = 600; //seconds
+        public static SizeBucket[] sizeBuckets = new SizeBucket[SIZEBUCKET_COUNT];
+        public static int randomSeed;
+
+        public static int pointerSize = 4;  //bytes
+        [ThreadStatic]
+        public static Random Rand;
+
+        public static int threadCount = 1;
+        public static bool timeBased = true;
+        public static int maxDepth = 10;
+        public static int maxHeapMB = 100;  //max heap in MB
+        public static long maxAllocation; //bytes
+        public static int regionSizeMB = 4; //MB
+        public static double EstimatedHeapSize = 0; //bytes
+        public static double EstimatedObjectCount = 0; //estimate how many objects we have
+        public static double AvgObjectSize = 0; //bytes
+
+        [ThreadStatic]
+        public static List<ObjectWrapper> staticArr = new List<ObjectWrapper>(2500);
+        [ThreadStatic]
+        public static List<Region> regionList = new List<Region>(2500);
+        public static int staticIndex = 0;
+        public static ObjectWrapper staticObject;
+
+
+
+        public static int Main(string[] args)
+        {
+            if (!ParseArgs(args))
+                return 101;
+
+            maxAllocation = maxHeapMB * 1024 * 1024;
+            Rand = new Random(randomSeed);
+            List<ObjectWrapper> Arr = new List<ObjectWrapper>(2500);
+
+                pointerSize = IntPtr.Size;
+
+            RunTest(Arr);
+            GC.KeepAlive(Arr);
+            return 100;
+
+        }
+
+
+        public static void AllocatingPhase(List<ObjectWrapper> Arr, int maxRegions)
+        {
+            int regionSize = regionSizeMB * 1024 * 1024;
+            //decide how many regions to allocate
+            long size = maxAllocation - (long)EstimatedHeapSize;
+            long regionsToAllocate = size / (long)(regionSize);
+
+            if (regionsToAllocate <= 0)
+            {
+                System.Threading.Thread.Sleep(1000);
+                return;
+            }
+            if (regionsToAllocate > maxRegions)
+                regionsToAllocate = maxRegions;
+            Console.WriteLine("Allocating {0} regions", regionsToAllocate);
+            for (long i = 0; i < regionsToAllocate; i++)
+            {
+                int spaceBucket = Rand.Next(0, sizeBuckets.Length);
+                int objectBucket = Rand.Next(0, sizeBuckets.Length);
+                int pinnedPercentage = 0;
+                if (i % 5 == 0)
+                    pinnedPercentage = Rand.Next(0, 10);
+                Region r = new Region(pinnedPercentage, sizeBuckets[spaceBucket].minsize, sizeBuckets[spaceBucket].maxsize, sizeBuckets[objectBucket].minsize, sizeBuckets[objectBucket].maxsize);
+                r.Initialize(Arr);
+                regionList.Add(r);
+                if (i % 3 == 0 && i > 0)
+                    DeleteSpaces();
+            }
+            DeleteSpaces();
+        }
+
+
+        //want to create fragmentation in Gen2; when objects in the "spaces" list get in gen2, clear the list.
+        public static void DeleteSpaces()
+        {
+            if (regionList.Count == 0)
+                return;
+            for (int i = regionList.Count - 1; i >= 0; i--)
+            {
+                if (regionList[i].ClearSpaces())
+                {
+                    regionList.RemoveAt(i);
+                }
+            }
+        }
+
+
+        public static void SteadyState(List<ObjectWrapper> Arr)
+        {
+            Console.WriteLine("Heap size=" + GC.GetTotalMemory(false));
+            Console.WriteLine("Estimated Heap size=" + EstimatedHeapSize);
+            EstimatedObjectCount = CountTotalObjects(Arr);
+            ClearVisitedFlag(Arr);
+            Console.WriteLine("Before shuffle:EstimatedObjectCount " + EstimatedObjectCount);
+            Console.WriteLine("Heap size=" + GC.GetTotalMemory(false));
+            int iterCount = (int)(EstimatedObjectCount / 30);
+            Console.WriteLine("Shuffle {0} times", iterCount);
+            for (int iter2 = 0; iter2 < iterCount; iter2++)
+            {
+         //       Console.WriteLine("Shuffle iter " + iter2);
+                ShuffleReferences(Arr);
+            }
+            EstimatedObjectCount = CountTotalObjects(Arr);
+            ClearVisitedFlag(Arr);
+            Console.WriteLine("After shuffle:EstimatedObjectCount " + EstimatedObjectCount);
+            Console.WriteLine("Heap size=" + GC.GetTotalMemory(false));
+            EstimatedHeapSize = EstimatedObjectCount * AvgObjectSize;
+            Console.WriteLine("Estimated Heap size=" + EstimatedHeapSize);
+            //randomly remove some objects
+
+            if (EstimatedObjectCount >100)
+                RemoveObjects(Arr);
+
+
+        }
+
+        public static void ShuffleReferences(List<ObjectWrapper> Arr)
+        {
+            ClearVisitedFlag(Arr);
+            //Console.WriteLine("Shuffle");
+            EstimatedObjectCount = CountTotalObjects(Arr);
+        //    Console.WriteLine("EstimatedObjectCount " + EstimatedObjectCount);
+            int randNumber = Rand.Next(0, (int)EstimatedObjectCount); //Console.WriteLine(randNumber);
+            int randNumber2 = Rand.Next(0, (int)EstimatedObjectCount); //Console.WriteLine(randNumber2);
+            PickObject(Arr, randNumber);
+          
+            ObjectWrapper Object1 = staticObject;
+            for (int i = 0; i < Object1.m_data.Length; i++)
+            {
+                Object1.m_data[i] = (byte)(Object1.m_data[i] + randNumber);
+            }
+            PickObject(Arr, randNumber2);
+            for (int i = 0; i < staticObject.m_data.Length; i++)
+            {
+                staticObject.m_data[i] = (byte)(staticObject.m_data[i] + randNumber2);
+            }
+          
+            if (Object1 != null)
+            {
+                Object1.ref1 = staticObject;
+            //    Console.Write("Set ref from {0}", Object1.m_dataSize);
+           //     if (staticObject != null)
+            //        Console.WriteLine("to " + staticObject.m_dataSize);
+            }
+        }
+
+        public static void PickObject(List<ObjectWrapper> Arr, int index)
+        {
+            ClearVisitedFlag(Arr);
+            staticObject=null;
+            staticIndex = 0;
+            for (int i = 0; i < Arr.Count; i++)
+            {
+                //Console.WriteLine("in Arr, pos=" + i);
+                if (staticObject != null)
+                    return;
+               // Console.WriteLine("now pick object in Arr, pos=" + i);
+                 PickObject(Arr[i], index);
+            }
+
+            for (int i = 0; i < staticArr.Count; i++)
+            {
+               // Console.WriteLine("in staticArr, pos=" + i);
+                if (staticObject != null)
+                    return;
+               // Console.WriteLine("now pick object in static Arr, pos=" + i);
+                 PickObject(staticArr[i], index);
+            }
+        }
+
+        public static void PickObject(ObjectWrapper o, int index)
+        {
+            if (o.visited)
+            {
+                return;
+            }
+            o.visited = true;
+       //    Console.WriteLine("Try Pick object" + staticIndex);
+  
+            if(staticObject != null)
+                return;
+            if (staticIndex == index)
+            {
+             //   Console.WriteLine("Object {0}; found for index {1}", o.m_dataSize, staticIndex);
+                staticObject = o;
+                return;
+            }
+           
+            staticIndex++;
+
+
+            if (o.ref1 != null && staticObject == null)
+                PickObject(o.ref1, index);
+            if (o.ref2 != null && staticObject == null)
+                PickObject(o.ref2, index);
+            if (o.ref3 != null && staticObject == null)
+                PickObject(o.ref3, index);
+            if (o.arrayRefs != null && staticObject == null)
+            {
+                for (int i = 0; i < o.arrayRefs.Length; i++)
+                {
+                    if (o.arrayRefs[i] != null && staticObject == null)
+                        PickObject(o.arrayRefs[i], index);
+                }
+            }
+        }
+        public static void RemoveObjects(List<ObjectWrapper> Arr)
+        {
+            /*
+            int CountPinned = CountPinnedObjects(Arr);
+            Console.WriteLine("pinned objects, before removing= " + CountPinned);
+            int Count = CountTotalObjects(Arr);
+            Console.WriteLine("total objects, before removing= " + Count);
+            Console.WriteLine("percentage pinned " + (float)CountPinned * 100.0f / (float)Count); 
+            */
+            Console.WriteLine("Removing Objects");
+            //Console.WriteLine("before: Arr.Count " + Arr.Count);
+            for (int i = Arr.Count - 1; i >= 0; i--)
+            {
+                if (i % 4 == 0)
+                {
+                    if (GC.GetGeneration(Arr[i]) == 2)
+                    {
+                        Arr.RemoveAt(i);
+                    }
+                }
+            }
+            //Console.WriteLine("after: Arr.Count" + Arr.Count);
+            //Console.WriteLine("before: staticArr.Count " + staticArr.Count);
+            for (int j = staticArr.Count - 1; j >= 0; j--)
+            {
+                if (j % 4 == 0)
+                {
+                    if (GC.GetGeneration(staticArr[j]) == 2)
+                        staticArr.RemoveAt(j);
+                }
+            }
+            //Console.WriteLine("after: staticArr.Count " + staticArr.Count);
+            // Console.WriteLine("before: gcHandleArr.Count " + gcHandleArr.Count);
+
+            //Console.WriteLine("before: gcHandleArr.Count " + gcHandleArr.Count);
+            //remove weak handles for dead objects
+
+            EstimatedObjectCount = CountTotalObjects(Arr);      
+            EstimatedHeapSize = EstimatedObjectCount * AvgObjectSize;
+            //Console.WriteLine("After removing objects: Estimated Heap size= " + EstimatedHeapSize);
+        }
+
+      
+
+        //estimate the total number of objects in the reference graph
+        public static int CountTotalObjects(List<ObjectWrapper> Arr)
+        {
+            ClearVisitedFlag(Arr);
+           // Console.WriteLine("Counting Objects..");
+            //use the "visited" table
+            int runningCount = 0;
+           
+            for (int i = 0; i < Arr.Count; i++)
+            {
+                runningCount += CountReferences(Arr[i]);
+            }
+
+            for (int i = 0; i < staticArr.Count; i++)
+            {
+                runningCount += CountReferences(staticArr[i]);
+            }
+           // Console.WriteLine("Counted {0} objects", runningCount);
+            return runningCount;
+        }
+
+        public static int CountPinnedObjects(List<ObjectWrapper> Arr)
+        {
+            ClearVisitedFlag(Arr);
+            Console.WriteLine("Counting Objects..");
+            //use the "visited" table
+            int runningCount = 0;
+           
+            for (int i = 0; i < Arr.Count; i++)
+            {
+                runningCount += CountPinnedReferences(Arr[i]);
+            }
+
+            for (int i = 0; i < staticArr.Count; i++)
+            {
+                runningCount += CountPinnedReferences(staticArr[i]);
+            }
+            Console.WriteLine("Counted {0} objects", runningCount);
+            return runningCount;
+        }
+
+        public static void ClearVisitedFlag(List<ObjectWrapper> Arr)
+        {
+           // Console.WriteLine("Clearing flag..");
+
+            for (int i = 0; i < Arr.Count; i++)
+            {
+                ClearVisitedFlag(Arr[i]);
+            }
+
+            for (int i = 0; i < staticArr.Count; i++)
+            {
+                ClearVisitedFlag(staticArr[i]);
+            }
+        }
+
+        //counts the refernces of this objects
+        public static int CountReferences(ObjectWrapper o)
+        {
+            if (o.visited)
+            {
+                return 0;
+            }
+            else
+                o.visited = true; ;
+            int count = 1;
+
+            if (o.ref1 != null)
+                count+= CountReferences(o.ref1);
+            if (o.ref2 != null)
+                 count+= CountReferences(o.ref2);
+            if (o.ref3 != null)
+                count+= CountReferences(o.ref3);
+            if (o.arrayRefs != null)
+            {
+                for (int i = 0; i < o.arrayRefs.Length; i++)
+                {
+                    if (o.arrayRefs[i] != null)
+                    {
+                        count += CountReferences(o.arrayRefs[i]);
+                    }
+                }
+            }
+            return count;
+        }
+
+        public static void ClearVisitedFlag(ObjectWrapper o)
+        {
+            if (!o.visited)
+            {
+                return;
+            }
+            else
+                o.visited = false;
+
+            if (o.ref1 != null)
+                ClearVisitedFlag(o.ref1);
+            if (o.ref2 != null)
+                ClearVisitedFlag(o.ref2);
+            if (o.ref3 != null)
+                ClearVisitedFlag(o.ref3);
+            if (o.arrayRefs != null)
+            {
+                for (int i = 0; i < o.arrayRefs.Length; i++)
+                {
+                    if (o.arrayRefs[i] != null)
+                    {
+                        ClearVisitedFlag(o.arrayRefs[i]);
+                    }
+                }
+            }
+           
+        }
+        //counts the pinned refernces of this objects
+        public static int CountPinnedReferences(ObjectWrapper o)
+        {
+            if (o.visited)
+            {
+                return 0;
+            }
+            else
+                o.visited=true;
+            int count = 0;
+            if (o.m_pinned)
+                count = 1;
+
+            if (o.ref1 != null)
+                count += CountPinnedReferences(o.ref1);
+            if (o.ref2 != null)
+                count += CountPinnedReferences(o.ref2);
+            if (o.ref3 != null)
+                count += CountPinnedReferences(o.ref3);
+            if (o.arrayRefs != null)
+            {
+                for (int i = 0; i < o.arrayRefs.Length; i++)
+                {
+                    if (o.arrayRefs[i] != null)
+                    {
+                        count += CountPinnedReferences(o.arrayRefs[i]);
+                    }
+                }
+            }
+            return count;
+        }
+   
+      
+
+        public static void UpdateAvg()
+        {
+            AvgObjectSize = (double)EstimatedHeapSize / (double)EstimatedObjectCount;
+            //Console.WriteLine("Avg object size " + AvgObjectSize);
+           
+        }
+
+        public static void AddRef(Object from, Object to)
+        {
+            Object[] arrFrom = from as Object[];
+            for (int i = 0; i < arrFrom.Length; i++)
+            {
+                if (arrFrom[i] == null)
+                {
+                    arrFrom[i] = to;
+                    break;
+                }
+            }
+
+        }
+
+    
+
+        public static void RunTest(List<ObjectWrapper> Arr)
+        {
+            System.Diagnostics.Stopwatch threadStopwatch = new System.Diagnostics.Stopwatch();
+            threadStopwatch.Start();
+
+            int iter = 0;
+            while (true)
+            {
+                Console.WriteLine("Allocating phase. Start at {0}", DateTime.Now);
+                AllocatingPhase(Arr, 20);
+
+                Console.WriteLine("starting steady state. Time is {0}", DateTime.Now);
+                SteadyState(Arr);
+                Console.WriteLine("End steady state. Time is {0}", DateTime.Now);
+                iter++;
+
+                if (timeBased)
+                {
+                    if (threadStopwatch.ElapsedMilliseconds / 1000 > timeout)
+                        break;
+                }
+                else //not timebased
+                {
+                    if (iter >= countIters)
+                        break;
+                }
+            }
+
+        }
+
+
+
+        public static void InitializeSizeBuckets()
+        {
+            sizeBuckets[0] = new SizeBucket(BUCKET1_MIN, BUCKET2_MIN);
+            sizeBuckets[1] = new SizeBucket(BUCKET2_MIN, BUCKET3_MIN);
+            sizeBuckets[2] = new SizeBucket(BUCKET3_MIN, BUCKET4_MIN);
+            sizeBuckets[3] = new SizeBucket(BUCKET4_MIN, BUCKETS_MAX);
+        }
+        /// Parse the arguments and also initialize values that are not set by args
+        public static bool ParseArgs(string[] args)
+        {
+            randomSeed = (int)DateTime.Now.Ticks;
+
+            try
+            {
+                for (int i = 0; i < args.Length; ++i)
+                {
+                    string currentArg = args[i]; //Console.WriteLine(currentArg);
+                    string currentArgValue;
+                    if (currentArg.StartsWith("-") || currentArg.StartsWith("/"))
+                    {
+                        currentArg = currentArg.Substring(1);
+                    }
+                    else
+                    {
+                        Console.WriteLine("Error! Unexpected argument {0}", currentArg);
+                        return false;
+                    }
+
+                    if (currentArg.StartsWith("?"))
+                    {
+                        Usage();
+                        return false;
+                    }
+                    else if (String.Compare(currentArg.ToLower(), "iter") == 0) // number of iterations
+                    {
+                        currentArgValue = args[++i];
+                        countIters = Int32.Parse(currentArgValue);
+                        timeBased = false;
+                    }
+                    else if (String.Compare(currentArg.ToLower(), "maxheapmb") == 0)
+                    {
+                        currentArgValue = args[++i];
+                        maxHeapMB = Int32.Parse(currentArgValue);
+                    }
+                    else if (String.Compare(currentArg.ToLower(), "regionsizemb") == 0)
+                    {
+                        currentArgValue = args[++i];
+                        regionSizeMB = Int32.Parse(currentArgValue);
+                    }
+                    else if (String.Compare(currentArg.ToLower(), "timeout") == 0) //seconds; if 0 run forever
+                    {
+                        currentArgValue = args[++i];
+                        timeout = Int64.Parse(currentArgValue);
+                        if (timeout == -1)
+                        {
+                            timeout = Int64.MaxValue;
+                        }
+                    }
+                    else if (String.Compare(currentArg.ToLower(), "randomseed") == 0) // number of iterations
+                    {
+                        currentArgValue = args[++i];
+                        randomSeed = Int32.Parse(currentArgValue);
+                    }
+                    else if (String.Compare(currentArg.ToLower(), "depth") == 0) // number of iterations
+                    {
+                        currentArgValue = args[++i];
+                        maxDepth = Int32.Parse(currentArgValue);
+                    }
+                    else
+                    {
+                        Console.WriteLine("Error! Unexpected argument {0}", currentArg);
+                        return false;
+                    }
+
+                }
+            }
+            catch (System.Exception e)
+            {
+                Console.WriteLine("Incorrect arguments");
+                Console.WriteLine(e.ToString());
+                return false;
+            }
+
+            //do some basic checking of the arguments
+            if (countIters < 1)
+            {
+                Console.WriteLine("Incorrect values for arguments");
+                return false;
+            }
+            InitializeSizeBuckets();
+
+            Console.WriteLine("Repro with: ");
+            Console.WriteLine("==============================");
+            if (timeBased)
+                Console.WriteLine("-timeout " + timeout);
+            else
+                Console.WriteLine("-iter " + countIters);
+            Console.WriteLine("-maxHeapMB " + maxHeapMB);
+            Console.WriteLine("-regionSizeMB " + regionSizeMB);
+            Console.WriteLine("-randomseed " + randomSeed);
+            Console.WriteLine("-depth " + maxDepth);
+            Console.WriteLine("==============================");
+            return true;
+        }
+
+
+        public static void Usage()
+        {
+            Console.WriteLine("ECO1 [options]");
+            Console.WriteLine("\nOptions");
+            Console.WriteLine("-? Display the usage and exit");
+            Console.WriteLine("-iter <num iterations> : specify number of iterations for the test, default is " + countIters);
+            Console.WriteLine("If using time based instead of iterations:");
+            Console.WriteLine("-timeout <seconds> : when to stop the test, default is " + timeout);
+            Console.WriteLine("-maxHeapMB <MB> : max heap size in MB to allocate, default is " + maxHeapMB);
+            Console.WriteLine("-regionSizeMB <MB> : regionSize, default is " + regionSizeMB);
+            Console.WriteLine("-depth <depth of refernce tree>, default is " + maxDepth);
+
+            Console.WriteLine("-randomseed <seed> : random seed(for repro)");
+        }
+
+        public class Region
+        {
+            public  List<Object> Spaces = new List<Object>(2500);
+
+            public int depth;
+            public int size = 0; //bytes
+            public float pinnedPercentage;
+            public int pinnedCount = 0;
+            public int objectCount = 0;
+            public int minObjectSize;
+            public int maxObjectsize;
+            public int minSpaceSize;
+            public int maxSpaceSize;
+
+            //create an empty region
+            public Region(float pinnedPercentage, int minSpace, int maxSpace, int minObject, int maxObject)
+            {
+                this.pinnedPercentage = pinnedPercentage;
+                minSpaceSize = minSpace;
+                maxSpaceSize = maxSpace;
+                minObjectSize = minObject;
+                maxObjectsize = maxObject;
+         
+            }
+
+            //add objects to region
+            public void Initialize(List<ObjectWrapper> Arr)
+            {
+                while (size < regionSizeMB*1024*1024)
+                {
+                    //create an object with the characteristics(size, pinned) of this region. The object is added either o the static array or to Arr
+                    bool useStatic = Rand.Next(0, 2) == 0 ? true : false;
+
+                    if (useStatic)
+                        staticArr.Add(ObjectWrapper.AddObject(this, 0, null));
+                    else
+                        Arr.Add(ObjectWrapper.AddObject(this, 0, null));
+
+                }
+
+                UpdateAvg();
+            }
+
+            public bool ClearSpaces()
+            {
+                if (Spaces.Count <= 0)
+                {
+                    Console.WriteLine("Spaces.Count <= 0");
+                    return false;
+                }
+                if (GC.GetGeneration(Spaces[Spaces.Count - 1]) == 2)
+                {
+                    Spaces.Clear();
+                    return true;
+                }
+                return false;
+            }
+         
+        }
+
+        public class ObjectWrapper
+        {
+            public bool visited = false;
+            public ObjectWrapper parent = null;
+            public GCHandle m_pinnedHandle;
+            public bool m_pinned = false;
+            public ObjectWrapper ref1;
+            public ObjectWrapper ref2;
+            public ObjectWrapper ref3;
+            public byte[] m_data;
+            public ObjectWrapper[] arrayRefs = null;
+            public int m_dataSize;
+            public int depth = 0;
+
+            public static ObjectWrapper AddObject(Region r, int depth, ObjectWrapper Parent)
+            {
+
+                if (r.size >= regionSizeMB * 1024 * 1024 || depth>maxDepth)
+                    return null;
+                byte[] Temp = new byte[Rand.Next(50, 200)];
+                int size = Rand.Next(r.minObjectSize, r.maxObjectsize);
+               
+                bool pinned = false;
+                if ((r.pinnedCount * 100.0 / (double)r.objectCount) < r.pinnedPercentage)
+                {
+                    pinned = true;
+                    r.pinnedCount++;
+                }
+                int randNumber = Rand.Next(0, 20);
+                bool arrayrefs = false;
+                if (randNumber == 1)
+                    arrayrefs = true;
+                int references = Rand.Next(0, 3);
+                int arrayrefCount = 0;
+                if (arrayrefs)
+                {
+                    arrayrefCount = Rand.Next(10, 100);
+                    references = Rand.Next(3, arrayrefCount);
+                }
+
+
+                ObjectWrapper ow = new ObjectWrapper(size, pinned, references, arrayrefs, arrayrefCount, depth);
+                if (randNumber == 7)
+                    ow.parent = Parent;
+
+                if (!arrayrefs) //object has up to 3 references to other objects
+                {
+                    if (references > 0)
+                    {
+                        ow.ref1 = AddObject(r, ow.depth+1, ow);
+                    }
+                    if (references > 1)
+                    {
+                        ow.ref2 = AddObject(r, ow.depth + 1, ow);
+                    }
+                    if (references > 2)
+                    {
+                        ow.ref3 = AddObject(r, ow.depth + 1, ow);
+                    }
+                }
+                else  //object has an array of references
+                {
+                    for (int i = 0; i < arrayrefCount; i++)
+                    {
+                        ow.arrayRefs[i] = AddObject(r, depth+1, ow);
+                    }
+                }
+                r.size += size;
+
+
+                int spaceSize = Rand.Next(r.minSpaceSize, r.maxSpaceSize);
+                r.Spaces.Add(new byte[spaceSize]);
+
+                r.size += spaceSize;
+                r.objectCount++;
+                EstimatedObjectCount++;
+                EstimatedHeapSize += size;
+                return ow;
+            }
+            public ObjectWrapper(int datasize, bool pinned, int references, bool arrayrefs, int arrayRefCount, int depth)
+            {
+                this.depth = depth;
+                //we want m_data to have an approximate size of dataSize
+                m_dataSize = datasize;  
+                m_pinned = pinned;
+            
+                m_data = new byte[datasize];
+                for (int i = 0; i < datasize; i++)
+                {
+                    m_data[i] = (byte)(references - i);
+                }
+                if(pinned)
+                    m_pinnedHandle = GCHandle.Alloc(m_data, GCHandleType.Pinned);
+
+                if (arrayrefs)
+                {
+                    arrayRefs = new ObjectWrapper[arrayRefCount];
+                }
+
+               
+            }
+            public void CleanUp()
+            {
+                if (m_pinned)
+                {
+                    if (m_pinnedHandle.IsAllocated)
+                    {
+                        m_pinnedHandle.Free();
+                    }
+                }
+                GC.SuppressFinalize(this);
+            }
+            ~ObjectWrapper()
+            {
+                CleanUp();
+            }
+
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Features/PartialCompaction/eco1.csproj b/src/coreclr/tests/src/GC/Features/PartialCompaction/eco1.csproj
new file mode 100644 (file)
index 0000000..c6021a3
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="ECO1.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/PartialCompaction/partialcompactiontest.cs b/src/coreclr/tests/src/GC/Features/PartialCompaction/partialcompactiontest.cs
new file mode 100644 (file)
index 0000000..4108765
--- /dev/null
@@ -0,0 +1,698 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Runtime.InteropServices;
+
+//Test for Partial Compaction
+//Goals: create fragmentation in Gen2
+//Allocation should not be too intense
+//For testing the concurrent phase of partial compaction: update references between objects
+//What the test does:
+// 1.Allocating phase: 
+//-Allocate n regions
+//-When objects get in Gen2 release the objects used to create spaces
+//-Create refs from objects in these regions to ephemeral objects
+// 2.Steady state 
+//- randomly change references between objects
+//- release some of the existing objects (to create fragmentation in the existing regions)
+// Repeat from 1.
+namespace PartialCompactionTest
+{
+    public class PartialCompactionTest
+    {
+   
+        //Define the size buckets:
+        public struct SizeBucket
+        {
+            public int minsize;
+            public int maxsize;
+            //public float percentage;  //percentage of objects that fall into this bucket
+            public SizeBucket(int min, int max)
+            {
+                //
+                minsize = min;
+                maxsize = max;
+            }
+
+        }
+
+        //Buckets are defined as following:
+        //Bucket1: 17 bytes to 200 bytes
+        //Bucket2: 200bytes to 1000 bytes
+        //Bucket3: 1000 bytes to 10000 bytes
+        //Bucket4: 10000 bytes to 80000 bytes
+        //The rest is over 85000 bytes (Large Object Heap)
+        private const int SIZEBUCKET_COUNT = 4;
+        private const int BUCKET1_MIN = 50;
+        private const int BUCKET2_MIN = 200;
+        private const int BUCKET3_MIN = 1000;
+        private const int BUCKET4_MIN = 10000;
+        private const int BUCKETS_MAX = 80000;
+        //////
+    
+        public const int DEFAULT_ITERATIONS = 100;
+        public static int countIters = DEFAULT_ITERATIONS;
+        public static long timeout = 600; //seconds
+        public static SizeBucket[] sizeBuckets = new SizeBucket[SIZEBUCKET_COUNT];
+        public static int randomSeed;
+        public static int pointerSize = 4;  //bytes
+        [ThreadStatic]
+        public static Random Rand;
+       
+        //new
+        public static bool timeBased = true;
+        public static int maxHeapMB = 100;  //max heap in MB
+        public static long maxAllocation; //bytes
+        public static int regionSizeMB = 4; //MB
+        public static double EstimatedHeapSize = 0; //bytes
+        public static double EstimatedObjectCount = 0; //estimate how many objects we have
+        public static List<Object> Visited = new List<Object>(2500);  //for estimating the objects count
+        public static double AvgObjectSize = 0; //bytes
+        public static List<Object> staticArr = new List<Object>(2500);
+        public static List<GCHandle> gcHandleArr = new List<GCHandle>(2500);
+        public static List<GCHandle> weakList = new List<GCHandle>(2500);
+        public static List<Region> regionList = new List<Region>(2500);
+        public static Object[] ephemeralList = new Object[2500];
+
+
+        public static int Main(string[] args)
+        {
+            if (!ParseArgs(args))
+                return 101;
+
+            maxAllocation = maxHeapMB * 1024 * 1024;
+            Rand = new Random(randomSeed);
+            List<Object> Arr = new List<Object>(2500);
+
+                pointerSize = IntPtr.Size;
+
+            RunTest(Arr);
+            GC.KeepAlive(Arr);
+            return 100;
+
+        }
+
+        public static Object CreateObject(int size, bool pinned)
+        {
+            if (!pinned)
+            {
+                int sz = size / pointerSize;
+                Object[] o = new Object[sz];
+                for (int i = 0; i < sz; i++)
+                {
+                    o[i] = null;
+                }
+                return o;
+            }
+            else
+            {
+                byte[] b = new byte[size];
+                for (int i = 0; i < size; i++)
+                {
+                    b[i] = 5;
+                }
+                return b;
+            }
+        }
+
+
+
+
+        public static void InitialAllocation(List<Object> Arr)
+        {
+            for (int i = 0; i < 5; i++)
+            {
+                Object[] o = new Object[3];
+                staticArr.Add(o);
+                weakList.Add(GCHandle.Alloc(o, GCHandleType.Weak));
+               
+            }
+            AllocatingPhase(Arr, 50);
+        }
+
+        public static void AllocatingPhase(List<Object> Arr, int maxRegions)
+        {
+            int regionSize = regionSizeMB * 1024 * 1024;
+            //decide how many regions to allocate
+            long size = maxAllocation - (long)EstimatedHeapSize;
+            long regionsToAllocate = size / (long)(regionSize);
+
+            if (regionsToAllocate <= 0)
+            {
+                System.Threading.Thread.Sleep(1000);
+                return;
+            }
+            if (regionsToAllocate > maxRegions)
+                regionsToAllocate = maxRegions;
+            Console.WriteLine("Allocating {0} regions", regionsToAllocate);
+            for (long i = 0; i < regionsToAllocate; i++)
+            {
+                int spaceBucket = Rand.Next(0, sizeBuckets.Length);
+                int objectBucket = Rand.Next(0, sizeBuckets.Length);
+                int pinnedPercentage = 0;
+                if(i%5==0)
+                    pinnedPercentage = Rand.Next(0, 10);
+                AllocateRegion(regionSize, pinnedPercentage, sizeBuckets[spaceBucket].minsize, sizeBuckets[spaceBucket].maxsize, sizeBuckets[objectBucket].minsize, sizeBuckets[objectBucket].maxsize, Arr);
+                 if(i%3==0 && i>0)
+                     DeleteSpaces();
+                 if (i % 3 == 0 && i > 3)
+                     CleanupRegions();
+            }
+            DeleteSpaces();
+        }
+
+
+        //want to create fragmentation in Gen2; when objects in the "spaces" list get in gen2, clear the list.
+        public static void DeleteSpaces()
+        {
+            if (regionList.Count == 0)
+                return;
+            for (int i = regionList.Count - 1; i >= 0; i--)
+            {
+                Region r = regionList[i];
+                if (r.Spaces.Count <= 0)
+                    continue;
+                if (GC.GetGeneration(r.Spaces[r.Spaces.Count - 1]) == 2)
+                {
+                    r.ReferenceEphemeralObjects();
+                    r.Spaces.Clear();
+                    r.Objects.Clear();
+                }
+            }
+        }
+
+        public static void CleanupRegions()
+        {
+            if (regionList.Count == 0)
+                return;
+            for (int i = regionList.Count - 1; i >= 0; i--)
+            {
+                Region r = regionList[i];
+                if (r.Ephemeral != null && r.Ephemeral.Count > 0)
+                {
+                    if (GC.GetGeneration(r.Ephemeral[0]) >= 1)
+                    {
+                        regionList.RemoveAt(i);
+                    }
+                }
+            }
+        }
+    
+        public static void SteadyState(List<Object> Arr)
+        {
+            Console.WriteLine("Heap size=" + GC.GetTotalMemory(false));
+            Console.WriteLine("Estimated Heap size=" + EstimatedHeapSize);
+            for (int iter2 = 0; iter2 < 100; iter2++)
+            {
+                UpdateReferences();
+            }
+            //randomly remove some objects
+
+            RemoveObjects(Arr);
+            for (int iter3 = 0; iter3 < 100; iter3++)
+            {
+                UpdateReferences();
+            }
+               
+         
+
+        }
+
+        public static void UpdateReferences()
+        {
+            for (int i = 0; i < weakList.Count; i++)
+            {
+                if (weakList[i].Target == null)
+                    continue;
+                Object[] OAr = weakList[i].Target as Object[];
+                if (OAr == null)
+                    continue;
+
+
+                for (int j = 0; j < OAr.Length; j++)
+                {
+                    if (OAr[j] != null)
+                    {
+                        int pos = Rand.Next(0, weakList.Count);
+                        if (weakList[pos] != null && weakList[pos].IsAllocated)
+                        {
+                            OAr[j] = weakList[pos].Target;
+                        }
+                    }
+                }
+            }
+        }
+
+        public static void RemoveObjects(List<Object> Arr)
+        {
+            Console.WriteLine("Removing Objects");
+            //Console.WriteLine("before: Arr.Count " + Arr.Count);
+            for(int i= Arr.Count-1; i>=0; i--)
+            {
+                if (i % 4 == 0)
+                {
+                    if(GC.GetGeneration(Arr[i])==2)
+                    Arr.RemoveAt(i);
+                }
+            }
+            //Console.WriteLine("after: Arr.Count" + Arr.Count);
+            //Console.WriteLine("before: staticArr.Count " + staticArr.Count);
+            for (int j = staticArr.Count - 1; j >= 0; j--)
+            {
+                if (j % 4 == 0)
+                {
+                    if (GC.GetGeneration(staticArr[j]) == 2)
+                    staticArr.RemoveAt(j);
+                }
+            }
+            //Console.WriteLine("after: staticArr.Count " + staticArr.Count);
+           // Console.WriteLine("before: gcHandleArr.Count " + gcHandleArr.Count);
+
+            for (int k = gcHandleArr.Count - 1; k >= 0; k--)
+            {
+                if (k % 2 == 0)
+                {
+                    if (GC.GetGeneration(gcHandleArr[k].Target) == 2)
+                    gcHandleArr[k].Free();
+                    gcHandleArr.RemoveAt(k);
+                }
+            }
+            //Console.WriteLine("before: gcHandleArr.Count " + gcHandleArr.Count);
+            //remove weak handles for dead objects
+            CleanupWeakReferenceArr();
+            int objectCount = CountTotalObjects(Arr);
+            Visited.Clear();
+            //if pinned objects are more than 3% remove all of them
+            if ((float)gcHandleArr.Count / (float)objectCount > 0.03f)
+            {
+                Console.WriteLine("removing all pinned objects");
+                RemoveAllPinnedObjects();
+            }
+            //Console.WriteLine("total count " + objectCount);
+            EstimatedHeapSize = objectCount * AvgObjectSize;
+            //Console.WriteLine("After removing objects: Estimated Heap size= " + EstimatedHeapSize);
+        }
+
+        public static void RemoveAllPinnedObjects()
+        {
+            for (int k = 0; k < gcHandleArr.Count; k++)
+            {
+                gcHandleArr[k].Free();
+            }
+            gcHandleArr.Clear();
+        }
+
+        //estimate the total number of objects in the reference graph
+        public static int CountTotalObjects(List<Object> Arr)
+        {
+            Visited.Clear();
+            Console.WriteLine("Counting Objects..");
+            //use the "visited" table
+            int runningCount = 0;
+           // runningCount += CountReferences(Arr[0]);
+            for (int i = 0; i < Arr.Count; i++)
+           {
+               runningCount+= CountReferences(Arr[i]);
+            }
+            
+            for (int i = 0; i < staticArr.Count; i++)
+            {
+                runningCount += CountReferences(staticArr[i]);
+            }
+            runningCount += gcHandleArr.Count;
+           
+            
+            return runningCount;
+        }
+
+        //counts the refernces of this objects
+        public static int CountReferences( Object o)
+        {
+            if (Visited.Contains(o))
+            {
+                return 0;
+            }
+            else
+                Visited.Add(o);
+            int count = 1;
+           
+            Object[] oArr = o as Object[];
+            if (oArr == null)
+                return count;
+            for (int i = 0; i < oArr.Length; i++)
+            {
+                if (oArr[i] != null)
+                {
+                    count += CountReferences(oArr[i]);
+                }
+            }
+           
+            return count;
+        }
+        public static void CleanupWeakReferenceArr()
+        {
+            for (int k = weakList.Count - 1; k >= 0; k--)
+            {
+                if (weakList[k] == null || !(weakList[k].IsAllocated))
+                {
+                    weakList.RemoveAt(k);
+                }
+                else if (weakList[k].Target == null)
+                {
+                    weakList[k].Free();
+                    weakList.RemoveAt(k);
+                }
+            }
+        }
+        public static int AllocateRegion(int regionSize, float pinnedPercentage, int minSpace, int maxSpace, int minObject, int maxObject, List<Object> Arr)
+        {
+            int sizeCounter = 0;
+            double pinnedCount = 0;
+            double objectCount = 0;
+            Object o;
+            
+            Region r = new Region();
+            regionList.Add(r);
+            while (sizeCounter < regionSize)
+            {
+                byte[] Temp = new byte[Rand.Next(50, 200)];
+                int objSize = Rand.Next(minObject, maxObject); //Console.WriteLine("Objsize " + objSize);
+                if ((pinnedCount * 100.0 / objectCount) < pinnedPercentage)
+                {
+                    AddPinnedObject(objSize);
+                    pinnedCount++;
+                }
+                else
+                {
+                    o = AddObject(objSize, Arr);
+                    r.Objects.Add(o);
+                }
+
+                int spaceSize = Rand.Next(minSpace, maxSpace);
+                r.Spaces.Add(new byte[spaceSize]);
+               
+                sizeCounter += objSize;
+                sizeCounter += spaceSize;
+                objectCount++;
+                EstimatedObjectCount ++;
+                EstimatedHeapSize += objSize;
+                
+            }
+
+            UpdateAvg();
+            return sizeCounter;
+        }
+
+        public static void UpdateAvg()
+        {
+            AvgObjectSize = (double)EstimatedHeapSize / (double)EstimatedObjectCount;
+            //Console.WriteLine("Avg object size " + AvgObjectSize);
+        }
+        public static void AddPinnedObject(int objSize)
+        {
+            gcHandleArr.Add(GCHandle.Alloc(CreateObject(objSize, true), GCHandleType.Pinned));
+        }
+
+        public static void AddRef(Object from, Object to)
+        {
+            Object[] arrFrom = from as Object[];
+            for (int i = 0; i < arrFrom.Length; i++)
+            {
+                if (arrFrom[i] == null)
+                {
+                    arrFrom[i] = to;
+                    break;
+                }
+            }
+
+        }
+
+        //add ref from this object to existing objects
+        public static void AddRefFrom(Object from)
+        {
+            int pos = Rand.Next(0, weakList.Count);
+            bool found = false;
+            while (!found)
+            {
+                pos = Rand.Next(0, weakList.Count);
+                if (weakList[pos] == null || !weakList[pos].IsAllocated)
+                    continue;
+                if (weakList[pos].Target != null)
+                {
+                    AddRef(from, weakList[pos].Target);
+                    found = true;
+                }
+            }
+        }
+
+        //add ref from this object to existing objects
+        public static void AddRefTo(Object to)
+        {
+            int pos = Rand.Next(0, weakList.Count);
+            bool found = false;
+            while (!found)
+            {
+                pos = Rand.Next(0, weakList.Count);
+                if (weakList[pos] == null || !weakList[pos].IsAllocated)
+                    continue;
+                if (weakList[pos].Target != null)
+                {
+                    AddRef(weakList[pos].Target, to);
+                    found = true;
+                }
+            }
+        }
+
+        //add as reference to existing objects
+        public static Object AddObject(int size, List<Object> Arr)
+        {
+            bool found = false;
+            Object[] o = new Object[size / pointerSize];
+            int r = Rand.Next(0, 10);
+            if (r == 0)
+            {
+                staticArr.Add(o);
+                //add ref from this object to existing objects
+                AddRefFrom(o);
+            }
+            else if (r == 1)
+            {
+                Arr.Add(o);
+                AddRefFrom(o);
+            }
+            else
+            {
+                //add as reference to existing objects
+                AddRefTo(o);
+                
+            }
+          
+            //find an empty place in array
+            found = false;
+            for (int i = 0; i < weakList.Count; i++)
+            {
+                if (weakList[i] == null || !weakList[i].IsAllocated)
+                {
+                    weakList[i] = GCHandle.Alloc(o, GCHandleType.Weak);
+                    found = true;
+                }
+            }
+            if(!found)
+                weakList.Add(GCHandle.Alloc(o, GCHandleType.Weak));
+            return o;
+        }
+
+        public static void AddEphemeralObject(int size)
+        {
+            for(int i=0; i<ephemeralList.Length; i++)
+            {
+                if(ephemeralList[i]==null || (GC.GetGeneration(ephemeralList[i])>=1))
+                {
+                    ephemeralList[i] = new byte[size];
+                    break;
+                }
+
+            }
+        }
+
+        public static void RunTest(List<Object> Arr)
+        {
+            System.Diagnostics.Stopwatch threadStopwatch = new System.Diagnostics.Stopwatch();
+            threadStopwatch.Start();
+            
+
+           
+            //Steady state: objects die and others are created
+
+            int iter = 0;
+            while (true)
+            {
+                Console.WriteLine("Allocating phase. Start at {0}", DateTime.Now);
+                if(iter==0)
+                    InitialAllocation(Arr);
+                else
+                    AllocatingPhase(Arr, 20);
+
+               Console.WriteLine("starting steady state. Time is {0}", DateTime.Now);
+               SteadyState(Arr);
+               Console.WriteLine("End steady state. Time is {0}", DateTime.Now);
+               iter++;
+
+               if (timeBased)
+               {
+                   if (threadStopwatch.ElapsedMilliseconds / 1000 > timeout)
+                       break;
+               }
+               else //not timebased
+               {
+                   if(iter>=countIters)
+                       break;
+               }
+            }
+
+        }
+
+       
+
+        public static void InitializeSizeBuckets()
+        {
+            sizeBuckets[0] = new SizeBucket(BUCKET1_MIN, BUCKET2_MIN);
+            sizeBuckets[1] = new SizeBucket(BUCKET2_MIN, BUCKET3_MIN);
+            sizeBuckets[2] = new SizeBucket(BUCKET3_MIN, BUCKET4_MIN);
+            sizeBuckets[3] = new SizeBucket(BUCKET4_MIN, BUCKETS_MAX);
+        }
+        /// Parse the arguments and also initialize values that are not set by args
+        public static bool ParseArgs(string[] args)
+        {
+            randomSeed = (int)DateTime.Now.Ticks;
+
+            try
+            {
+                for (int i = 0; i < args.Length; ++i)
+                {
+                    string currentArg = args[i]; //Console.WriteLine(currentArg);
+                    string currentArgValue;
+                    if (currentArg.StartsWith("-") || currentArg.StartsWith("/"))
+                    {
+                        currentArg = currentArg.Substring(1);
+                    }
+                    else
+                    {
+                        Console.WriteLine("Error! Unexpected argument {0}", currentArg);
+                        return false;
+                    }
+
+                    if (currentArg.StartsWith("?"))
+                    {
+                        Usage();
+                        return false;
+                    }
+                    else if (String.Compare(currentArg.ToLower(), "iter") == 0) // number of iterations
+                    {
+                        currentArgValue = args[++i];
+                        countIters = Int32.Parse(currentArgValue);
+                        timeBased = false;
+                    }
+                    else if (String.Compare(currentArg.ToLower(), "maxheapmb") == 0)
+                    {
+                        currentArgValue = args[++i];
+                        maxHeapMB = Int32.Parse(currentArgValue);
+                    }
+                    else if (String.Compare(currentArg.ToLower(), "regionsizemb") == 0)
+                    {
+                        currentArgValue = args[++i];
+                        regionSizeMB = Int32.Parse(currentArgValue);
+                    }             
+                    else if (String.Compare(currentArg.ToLower(), "timeout") == 0) //seconds; if 0 run forever
+                    {
+                        currentArgValue = args[++i];
+                        timeout = Int64.Parse(currentArgValue);
+                        if (timeout == -1)
+                        {
+                            timeout = Int64.MaxValue;
+                        }
+                    }
+                    else if (String.Compare(currentArg.ToLower(), "randomseed") == 0) // number of iterations
+                    {
+                        currentArgValue = args[++i];
+                        randomSeed = Int32.Parse(currentArgValue);
+                    }
+                    else
+                    {
+                        Console.WriteLine("Error! Unexpected argument {0}", currentArg);
+                        return false;
+                    }
+
+                }
+            }
+            catch (System.Exception e)
+            {
+                Console.WriteLine("Incorrect arguments");
+                Console.WriteLine(e.ToString());
+                return false;
+            }
+
+            //do some basic checking of the arguments
+            if (countIters < 1 )
+            {
+                Console.WriteLine("Incorrect values for arguments");
+                return false;
+            }
+            InitializeSizeBuckets();
+
+            Console.WriteLine("Repro with: ");
+            Console.WriteLine("==============================");
+            if(timeBased)
+                Console.WriteLine("-timeout " + timeout);
+            else
+                Console.WriteLine("-iter " + countIters);
+            Console.WriteLine("-maxHeapMB " + maxHeapMB);
+            Console.WriteLine("-regionSizeMB " + regionSizeMB);        
+            Console.WriteLine("-randomseed " + randomSeed);
+            Console.WriteLine("==============================");
+            return true;
+        }
+
+
+        public static void Usage()
+        {
+            Console.WriteLine("PartialCompactionTest [options]");
+            Console.WriteLine("\nOptions");
+            Console.WriteLine("-? Display the usage and exit");
+            Console.WriteLine("-iter <num iterations> : specify number of iterations for the test, default is " + countIters);
+            Console.WriteLine("If using time based instead of iterations:");
+            Console.WriteLine("-timeout <seconds> : when to stop the test, default is " + timeout);
+            Console.WriteLine("-maxHeapMB <MB> : max heap size in MB to allocate, default is " + maxHeapMB);
+            Console.WriteLine("-regionSizeMB <MB> : regionSize, default is " + regionSizeMB);
+     
+            Console.WriteLine("-randomseed <seed> : random seed(for repro)");
+        }
+
+        public class Region
+        {
+            public List<Object> Spaces = new List<Object>(2500);
+            public List<Object> Objects = new List<Object>(2500);
+            public List<Object> Ephemeral = new List<Object>(2500);
+            public void ReferenceEphemeralObjects()
+            {
+                //create refs from ephemeral objects to gen2 objects
+                if (GC.GetGeneration(Objects[0]) == 2)
+                {
+                    int size = Rand.Next(30, 20000);
+                    Object[] eph = new Object[size];
+                    Ephemeral.Add(eph);
+                    AddRef(eph, Objects[Rand.Next(0, Objects.Count)]);
+                }
+                Objects.Clear();
+            }
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Features/PartialCompaction/partialcompactiontest.csproj b/src/coreclr/tests/src/GC/Features/PartialCompaction/partialcompactiontest.csproj
new file mode 100644 (file)
index 0000000..8ccc632
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="PartialCompactionTest.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/PartialCompaction/partialcompactionwloh.cs b/src/coreclr/tests/src/GC/Features/PartialCompaction/partialcompactionwloh.cs
new file mode 100644 (file)
index 0000000..6f0ea57
--- /dev/null
@@ -0,0 +1,758 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Runtime.InteropServices;
+using System.Runtime;
+
+//Test for Partial Compaction
+//Goals: create fragmentation in Gen2
+//Allocation should not be too intense
+//For testing the concurrent phase of partial compaction: update references between objects
+//This test also had LOH objects and creates fragmentation in LOH
+//What the test does:
+// 1.Allocating phase: 
+//-Allocate n regions
+//-When objects get in Gen2 release the objects used to create spaces
+//-Create refs from objects in these regions to ephemeral objects
+// 2.Steady state 
+//- randomly change references between objects
+//- release some of the existing objects (to create fragmentation in the existing regions)
+// Repeat from 1.
+namespace PartialCompactionTest
+{
+    public class PartialCompactionTest
+    {
+   
+        //Define the size buckets:
+        public struct SizeBucket
+        {
+            public int minsize;
+            public int maxsize;
+            //public float percentage;  //percentage of objects that fall into this bucket
+            public SizeBucket(int min, int max)
+            {
+                //
+                minsize = min;
+                maxsize = max;
+            }
+
+        }
+
+        //Buckets are defined as following:
+        //Bucket1: 17 bytes to 200 bytes
+        //Bucket2: 200bytes to 1000 bytes
+        //Bucket3: 1000 bytes to 10000 bytes
+        //Bucket4: 10000 bytes to 80000 bytes
+        //The rest is over 85000 bytes (Large Object Heap)
+        private const int SIZEBUCKET_COUNT = 4;
+        private const int BUCKET1_MIN = 50;
+        private const int BUCKET2_MIN = 200;
+        private const int BUCKET3_MIN = 1000;
+        private const int BUCKET4_MIN = 10000;
+        private const int BUCKETS_MAX = 80000;
+        //////
+    
+        public const int DEFAULT_ITERATIONS = 100;
+        public static int countIters = DEFAULT_ITERATIONS;
+        public static long timeout = 600; //seconds
+        public static SizeBucket[] sizeBuckets = new SizeBucket[SIZEBUCKET_COUNT];
+        public static int randomSeed;
+        public static int pointerSize = 4;  //bytes
+        [ThreadStatic]
+        public static Random Rand;
+       
+        //new
+        public static bool timeBased = true;
+        public static int maxHeapMB = 100;  //max heap in MB
+        public static long maxAllocation; //bytes
+        public static int regionSizeMB = 4; //MB
+        public static double EstimatedHeapSize = 0; //bytes
+        public static double EstimatedObjectCount = 0; //estimate how many objects we have
+        public static List<Object> Visited = new List<Object>(2500);  //for estimating the objects count
+        public static double AvgObjectSize = 0; //bytes
+        public static List<Object> staticArr = new List<Object>(2500);
+        public static List<GCHandle> gcHandleArr = new List<GCHandle>(2500);
+        public static List<GCHandle> weakList = new List<GCHandle>(2500);
+        public static List<Region> regionList = new List<Region>(2500);
+        public static Object[] ephemeralList = new Object[2500];
+
+
+        public static int Main(string[] args)
+        {
+            if (!ParseArgs(args))
+                return 101;
+
+            maxAllocation = maxHeapMB * 1024 * 1024;
+            Rand = new Random(randomSeed);
+            List<Object> Arr = new List<Object>(2500);
+
+                pointerSize = IntPtr.Size;
+
+            RunTest(Arr);
+            GC.KeepAlive(Arr);
+            return 100;
+
+        }
+
+        public static Object CreateObject(int size, bool pinned)
+        {
+            if (!pinned)
+            {
+                int sz = size / pointerSize;
+                Object[] o = new Object[sz];
+                for (int i = 0; i < sz; i++)
+                {
+                    o[i] = null;
+                }
+                return o;
+            }
+            else
+            {
+                byte[] b = new byte[size];
+                for (int i = 0; i < size; i++)
+                {
+                    b[i] = 5;
+                }
+                return b;
+            }
+        }
+
+
+
+
+        public static void InitialAllocation(List<Object> Arr)
+        {
+            for (int i = 0; i < 5; i++)
+            {
+                Object[] o = new Object[3];
+                staticArr.Add(o);
+                weakList.Add(GCHandle.Alloc(o, GCHandleType.Weak));
+               
+            }
+            AllocatingPhase(Arr, 50);
+        }
+
+        public static void AllocatingPhase(List<Object> Arr, int maxRegions)
+        {
+            int regionSize = regionSizeMB * 1024 * 1024;
+            //decide how many regions to allocate
+            long size = maxAllocation - (long)EstimatedHeapSize;
+            long regionsToAllocate = size / (long)(regionSize);
+
+            if (regionsToAllocate <= 0)
+            {
+                System.Threading.Thread.Sleep(1000);
+                return;
+            }
+            if (regionsToAllocate > maxRegions)
+                regionsToAllocate = maxRegions;
+            Console.WriteLine("Allocating {0} regions", regionsToAllocate);
+            for (long i = 0; i < regionsToAllocate; i++)
+            {
+                bool LOH = false;
+                int randNumber = Rand.Next(0, 20);
+                if (randNumber == 5)
+                    LOH = true;
+
+                int pinnedPercentage = 0;
+                if (i % 5 == 0)
+                    pinnedPercentage = Rand.Next(0, 10);
+
+                if (!LOH)
+                {
+                    int spaceBucket = Rand.Next(0, sizeBuckets.Length);
+                    int objectBucket = Rand.Next(0, sizeBuckets.Length);
+
+                    AllocateRegion(regionSize, pinnedPercentage, sizeBuckets[spaceBucket].minsize, sizeBuckets[spaceBucket].maxsize, sizeBuckets[objectBucket].minsize, sizeBuckets[objectBucket].maxsize, Arr);
+                }
+                else
+                {
+                    Console.WriteLine("Allocating in LOH");
+                    int minsize = 85000;
+                    int maxsize = 200000;
+                    AllocateRegion(regionSize, pinnedPercentage, minsize, maxsize, minsize, maxsize, Arr);
+                }
+                 if(i%3==0 && i>0)
+                     DeleteSpaces();
+                 if (i % 3 == 0 && i > 3)
+                     CleanupRegions();
+            }
+            DeleteSpaces();
+        }
+
+
+        //want to create fragmentation in Gen2; when objects in the "spaces" list get in gen2, clear the list.
+        public static void DeleteSpaces()
+        {
+            if (regionList.Count == 0)
+                return;
+            for (int i = regionList.Count - 1; i >= 0; i--)
+            {
+                Region r = regionList[i];
+                if (r.Spaces.Count <= 0)
+                    continue;
+                if (GC.GetGeneration(r.Spaces[r.Spaces.Count - 1]) == 2)
+                {
+                    r.ReferenceEphemeralObjects();
+                    r.Spaces.Clear();
+                    r.Objects.Clear();
+                }
+            }
+        }
+
+        public static void CleanupRegions()
+        {
+            if (regionList.Count == 0)
+                return;
+            for (int i = regionList.Count - 1; i >= 0; i--)
+            {
+                Region r = regionList[i];
+                if (r.Ephemeral != null && r.Ephemeral.Count > 0)
+                {
+                    if (GC.GetGeneration(r.Ephemeral[0]) >= 1)
+                    {
+                        regionList.RemoveAt(i);
+                    }
+                }
+            }
+        }
+    
+        public static void SteadyState(List<Object> Arr)
+        {
+            Console.WriteLine("Heap size=" + GC.GetTotalMemory(false));
+            Console.WriteLine("Estimated Heap size=" + EstimatedHeapSize);
+            for (int iter2 = 0; iter2 < 100; iter2++)
+            {
+                UpdateReferences();
+                int randnumber2 = Rand.Next(0, 3);
+                if (iter2 % 50 == 0 && randnumber2==2)
+                {
+                    Console.WriteLine("Setting LOH compaction mode & collect");
+                    GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
+                }
+            }
+            //randomly remove some objects
+
+            RemoveObjects(Arr);
+            for (int iter3 = 0; iter3 < 100; iter3++)
+            {
+                UpdateReferences();
+            }
+               
+         
+
+        }
+
+        public static void UpdateReferences()
+        {
+            for (int i = 0; i < weakList.Count; i++)
+            {
+                if (weakList[i].Target == null)
+                    continue;
+                Object[] OAr = weakList[i].Target as Object[];
+                if (OAr == null)
+                    continue;
+
+
+                for (int j = 0; j < OAr.Length; j++)
+                {
+                    if (OAr[j] != null)
+                    {
+                        int pos = Rand.Next(0, weakList.Count);
+                        if (weakList[pos] != null && weakList[pos].IsAllocated)
+                        {
+                            OAr[j] = weakList[pos].Target;
+                        }
+                    }
+                }
+            }
+        }
+
+        public static void RemoveObjects(List<Object> Arr)
+        {
+            Console.WriteLine("Removing Objects");
+            //Console.WriteLine("before: Arr.Count " + Arr.Count);
+            for(int i= Arr.Count-1; i>=0; i--)
+            {
+                if (i % 4 == 0)
+                {
+                    if(GC.GetGeneration(Arr[i])==2)
+                    Arr.RemoveAt(i);
+                }
+            }
+            //Console.WriteLine("after: Arr.Count" + Arr.Count);
+            //Console.WriteLine("before: staticArr.Count " + staticArr.Count);
+            for (int j = staticArr.Count - 1; j >= 0; j--)
+            {
+                if (j % 4 == 0)
+                {
+                    if (GC.GetGeneration(staticArr[j]) == 2)
+                    staticArr.RemoveAt(j);
+                }
+            }
+            //Console.WriteLine("after: staticArr.Count " + staticArr.Count);
+           // Console.WriteLine("before: gcHandleArr.Count " + gcHandleArr.Count);
+            for (int k = gcHandleArr.Count - 1; k >= 0; k--)
+            {
+                if (k % 2 == 0)
+                {
+                    if (GC.GetGeneration(gcHandleArr[k].Target) == 2)
+                    gcHandleArr[k].Free();
+                    gcHandleArr.RemoveAt(k);
+                }
+            }
+            //Console.WriteLine("after: gcHandleArr.Count " + gcHandleArr.Count);
+            //remove weak handles for dead objects
+            CleanupWeakReferenceArr();
+            int objectCount = CountTotalObjects(Arr);
+            Visited.Clear();
+            //if pinned objects are more than 3% remove all of them
+            if ((float)gcHandleArr.Count / (float)objectCount > 0.03f)
+            {
+                Console.WriteLine("removing all pinned objects");
+                RemoveAllPinnedObjects();
+            }
+            //Console.WriteLine("total count " + objectCount);
+            EstimatedHeapSize = objectCount * AvgObjectSize;
+            //Console.WriteLine("After removing objects: Estimated Heap size= " + EstimatedHeapSize);
+        }
+
+        public static void RemoveAllPinnedObjects()
+        {
+            for (int k = 0; k < gcHandleArr.Count; k++)
+            {
+                gcHandleArr[k].Free();
+            }
+            gcHandleArr.Clear();
+        }
+        //estimate the total number of objects in the reference graph
+        public static int CountTotalObjects(List<Object> Arr)
+        {
+            Visited.Clear();
+            Console.WriteLine("Counting Objects..");
+            //use the "visited" table
+            int runningCount = 0;
+           // runningCount += CountReferences(Arr[0]);
+            for (int i = 0; i < Arr.Count; i++)
+           {
+               runningCount+= CountReferences(Arr[i]);
+            }
+            
+            for (int i = 0; i < staticArr.Count; i++)
+            {
+                runningCount += CountReferences(staticArr[i]);
+            }
+            runningCount += gcHandleArr.Count;
+
+            Console.WriteLine("Pinned GCHandles " + gcHandleArr.Count);
+            
+            return runningCount;
+        }
+
+        //counts the refernces of this objects
+        public static int CountReferences( Object o)
+        {
+            if (Visited.Contains(o))
+            {
+                return 0;
+            }
+            else
+                Visited.Add(o);
+            int count = 1;
+           
+            Object[] oArr = o as Object[];
+            if (oArr == null)
+                return count;
+            for (int i = 0; i < oArr.Length; i++)
+            {
+                if (oArr[i] != null)
+                {
+                    count += CountReferences(oArr[i]);
+                }
+            }
+           
+            return count;
+        }
+        public static void CleanupWeakReferenceArr()
+        {
+            for (int k = weakList.Count - 1; k >= 0; k--)
+            {
+                if (weakList[k] == null || !(weakList[k].IsAllocated))
+                {
+                    weakList.RemoveAt(k);
+                }
+                else if (weakList[k].Target == null)
+                {
+                    weakList[k].Free();
+                    weakList.RemoveAt(k);
+                }
+            }
+        }
+        public static int AllocateRegion(int regionSize, float pinnedPercentage, int minSpace, int maxSpace, int minObject, int maxObject, List<Object> Arr)
+        {
+            int sizeCounter = 0;
+            double pinnedCount = 0;
+            double objectCount = 0;
+            Object o;
+            
+            Region r = new Region();
+            regionList.Add(r);
+            while (sizeCounter < regionSize)
+            {
+                byte[] Temp = new byte[Rand.Next(50, 200)];
+                int objSize = Rand.Next(minObject, maxObject); //Console.WriteLine("Objsize " + objSize);
+                if ((pinnedCount * 100.0 / objectCount) < pinnedPercentage)
+                {
+                    AddPinnedObject(objSize);
+                    pinnedCount++;
+                }
+                else
+                {
+                    o = AddObject(objSize, Arr);
+                    r.Objects.Add(o);
+                }
+
+                int spaceSize = Rand.Next(minSpace, maxSpace);
+                r.Spaces.Add(new byte[spaceSize]);
+                sizeCounter += objSize;
+                sizeCounter += spaceSize;
+                objectCount++;
+                EstimatedObjectCount ++;
+                EstimatedHeapSize += objSize;
+                
+            }
+            //Console.WriteLine("Pinned objects in region: " + pinnedCount);
+           // Console.WriteLine("Allocated {0} objects per this region", objectCount);
+           // Console.WriteLine("Allocated {0} bytes per this region including spaces", sizeCounter);
+            UpdateAvg();
+            return sizeCounter;
+        }
+
+        public static void UpdateAvg()
+        {
+            AvgObjectSize = (double)EstimatedHeapSize / (double)EstimatedObjectCount;
+            //Console.WriteLine("Avg object size " + AvgObjectSize);
+        }
+        public static void AddPinnedObject(int objSize)
+        {
+            gcHandleArr.Add(GCHandle.Alloc(CreateObject(objSize, true), GCHandleType.Pinned));
+        }
+
+        public static void AddRef(Object from, Object to)
+        {
+            Object[] arrFrom = from as Object[];
+            for (int i = 0; i < arrFrom.Length; i++)
+            {
+                if (arrFrom[i] == null)
+                {
+                    arrFrom[i] = to;
+                    break;
+                }
+            }
+
+        }
+
+        //add ref from this object to existing objects
+        public static void AddRefFrom(Object from)
+        {
+            int pos = Rand.Next(0, weakList.Count);
+            bool found = false;
+            while (!found)
+            {
+                pos = Rand.Next(0, weakList.Count);
+                if (weakList[pos] == null || !weakList[pos].IsAllocated)
+                    continue;
+                if (weakList[pos].Target != null)
+                {
+                    AddRef(from, weakList[pos].Target);
+                    found = true;
+                }
+            }
+        }
+
+        //add ref from this object to existing objects
+        public static void AddRefTo(Object to)
+        {
+            int pos = Rand.Next(0, weakList.Count);
+            bool found = false;
+            while (!found)
+            {
+                pos = Rand.Next(0, weakList.Count);
+                if (weakList[pos] == null || !weakList[pos].IsAllocated)
+                    continue;
+                if (weakList[pos].Target != null)
+                {
+                    AddRef(weakList[pos].Target, to);
+                    found = true;
+                }
+            }
+        }
+
+        //add as reference to existing objects
+        public static Object AddObject(int size, List<Object> Arr)
+        {
+            bool found = false;
+            Object[] o = new Object[size / pointerSize];
+            int r = Rand.Next(0, 10);
+            if (r == 0)
+            {
+                staticArr.Add(o);
+                //add ref from this object to existing objects
+                AddRefFrom(o);
+            }
+            else if (r == 1)
+            {
+                Arr.Add(o);
+                AddRefFrom(o);
+            }
+            else
+            {
+                //add as reference to existing objects
+                AddRefTo(o);
+                
+            }
+          
+            //find an empty place in array
+            found = false;
+            for (int i = 0; i < weakList.Count; i++)
+            {
+                if (weakList[i] == null || !weakList[i].IsAllocated)
+                {
+                    weakList[i] = GCHandle.Alloc(o, GCHandleType.Weak);
+                    found = true;
+                }
+            }
+            if(!found)
+                weakList.Add(GCHandle.Alloc(o, GCHandleType.Weak));
+            return o;
+        }
+
+        public static void AddEphemeralObject(int size)
+        {
+            for(int i=0; i<ephemeralList.Length; i++)
+            {
+                if(ephemeralList[i]==null || (GC.GetGeneration(ephemeralList[i])>=1))
+                {
+                    ephemeralList[i] = new byte[size];
+                    break;
+                }
+
+            }
+        }
+
+        public static void RunTest(List<Object> Arr)
+        {
+            System.Diagnostics.Stopwatch threadStopwatch = new System.Diagnostics.Stopwatch();
+            threadStopwatch.Start();
+            
+
+           
+            //Steady state: objects die and others are created
+
+            int iter = 0;
+            while (true)
+            {
+                Console.WriteLine("Iteration# " + iter);
+                int randnumber = Rand.Next(0, 30);
+                if (randnumber == 1)
+                {
+                    Console.WriteLine("Setting LOH compaction mode");
+                    GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
+                }
+                int randnumber2 = Rand.Next(0, 30);
+                if (randnumber2 == 1)
+                {
+                    Console.WriteLine("GC.Collect");
+                    GC.Collect();
+                }
+
+                Console.WriteLine("Allocating phase. Start at {0}", DateTime.Now);
+                if(iter==0)
+                    InitialAllocation(Arr);
+                else
+                    AllocatingPhase(Arr, 20);
+
+                if (randnumber == 2)
+                {
+                    Console.WriteLine("Setting LOH compaction mode");
+                    GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
+                }
+                if (randnumber2 == 2)
+                {
+                    Console.WriteLine("GC.Collect");
+                    GC.Collect();
+                }
+               Console.WriteLine("starting steady state. Time is {0}", DateTime.Now);
+               SteadyState(Arr);
+               Console.WriteLine("End steady state. Time is {0}", DateTime.Now);
+               if (randnumber == 3)
+               {
+                   Console.WriteLine("Setting LOH compaction mode");
+                   GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
+               }
+               if (randnumber2 == 3)
+               {
+                   Console.WriteLine("GC.Collect");
+                   GC.Collect();
+               }
+               iter++;
+
+               if (timeBased)
+               {
+                   if (threadStopwatch.ElapsedMilliseconds / 1000 > timeout)
+                       break;
+               }
+               else //not timebased
+               {
+                   if(iter>=countIters)
+                       break;
+               }
+            }
+
+        }
+
+       
+
+        public static void InitializeSizeBuckets()
+        {
+            sizeBuckets[0] = new SizeBucket(BUCKET1_MIN, BUCKET2_MIN);
+            sizeBuckets[1] = new SizeBucket(BUCKET2_MIN, BUCKET3_MIN);
+            sizeBuckets[2] = new SizeBucket(BUCKET3_MIN, BUCKET4_MIN);
+            sizeBuckets[3] = new SizeBucket(BUCKET4_MIN, BUCKETS_MAX);
+        }
+        /// Parse the arguments and also initialize values that are not set by args
+        public static bool ParseArgs(string[] args)
+        {
+            randomSeed = (int)DateTime.Now.Ticks;
+
+            try
+            {
+                for (int i = 0; i < args.Length; ++i)
+                {
+                    string currentArg = args[i]; //Console.WriteLine(currentArg);
+                    string currentArgValue;
+                    if (currentArg.StartsWith("-") || currentArg.StartsWith("/"))
+                    {
+                        currentArg = currentArg.Substring(1);
+                    }
+                    else
+                    {
+                        Console.WriteLine("Error! Unexpected argument {0}", currentArg);
+                        return false;
+                    }
+
+                    if (currentArg.StartsWith("?"))
+                    {
+                        Usage();
+                        return false;
+                    }
+                    else if (String.Compare(currentArg.ToLower(), "iter") == 0) // number of iterations
+                    {
+                        currentArgValue = args[++i];
+                        countIters = Int32.Parse(currentArgValue);
+                        timeBased = false;
+                    }
+                    else if (String.Compare(currentArg.ToLower(), "maxheapmb") == 0)
+                    {
+                        currentArgValue = args[++i];
+                        maxHeapMB = Int32.Parse(currentArgValue);
+                    }
+                    else if (String.Compare(currentArg.ToLower(), "regionsizemb") == 0)
+                    {
+                        currentArgValue = args[++i];
+                        regionSizeMB = Int32.Parse(currentArgValue);
+                    }             
+                    else if (String.Compare(currentArg.ToLower(), "timeout") == 0) //seconds; if 0 run forever
+                    {
+                        currentArgValue = args[++i];
+                        timeout = Int64.Parse(currentArgValue);
+                        if (timeout == -1)
+                        {
+                            timeout = Int64.MaxValue;
+                        }
+                    }
+                    else if (String.Compare(currentArg.ToLower(), "randomseed") == 0) // number of iterations
+                    {
+                        currentArgValue = args[++i];
+                        randomSeed = Int32.Parse(currentArgValue);
+                    }
+                    else
+                    {
+                        Console.WriteLine("Error! Unexpected argument {0}", currentArg);
+                        return false;
+                    }
+
+                }
+            }
+            catch (System.Exception e)
+            {
+                Console.WriteLine("Incorrect arguments");
+                Console.WriteLine(e.ToString());
+                return false;
+            }
+
+            //do some basic checking of the arguments
+            if (countIters < 1 )
+            {
+                Console.WriteLine("Incorrect values for arguments");
+                return false;
+            }
+            InitializeSizeBuckets();
+
+            Console.WriteLine("Repro with: ");
+            Console.WriteLine("==============================");
+            if(timeBased)
+                Console.WriteLine("-timeout " + timeout);
+            else
+                Console.WriteLine("-iter " + countIters);
+            Console.WriteLine("-maxHeapMB " + maxHeapMB);
+            Console.WriteLine("-regionSizeMB " + regionSizeMB);        
+            Console.WriteLine("-randomseed " + randomSeed);
+            Console.WriteLine("==============================");
+            return true;
+        }
+
+
+        public static void Usage()
+        {
+            Console.WriteLine("PartialCompactionTest [options]");
+            Console.WriteLine("\nOptions");
+            Console.WriteLine("-? Display the usage and exit");
+            Console.WriteLine("-iter <num iterations> : specify number of iterations for the test, default is " + countIters);
+            Console.WriteLine("If using time based instead of iterations:");
+            Console.WriteLine("-timeout <seconds> : when to stop the test, default is " + timeout);
+            Console.WriteLine("-maxHeapMB <MB> : max heap size in MB to allocate, default is " + maxHeapMB);
+            Console.WriteLine("-regionSizeMB <MB> : regionSize, default is " + regionSizeMB);
+     
+            Console.WriteLine("-randomseed <seed> : random seed(for repro)");
+        }
+
+        public class Region
+        {
+            public List<Object> Spaces = new List<Object>(2500);
+            public List<Object> Objects = new List<Object>(2500);
+            public List<Object> Ephemeral = new List<Object>(2500);
+            public void ReferenceEphemeralObjects()
+            {
+                //create refs from ephemeral objects to gen2 objects
+                if (GC.GetGeneration(Objects[0]) == 2)
+                {
+                    int size = Rand.Next(30, 20000);
+                    Object[] eph = new Object[size];
+                    Ephemeral.Add(eph);
+                    AddRef(eph, Objects[Rand.Next(0, Objects.Count)]);
+                }
+                Objects.Clear();
+            }
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Features/PartialCompaction/partialcompactionwloh.csproj b/src/coreclr/tests/src/GC/Features/PartialCompaction/partialcompactionwloh.csproj
new file mode 100644 (file)
index 0000000..905da65
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="PartialCompactionwLOH.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
index 34a16eb..c37c71b 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
index 0f12466..db3a484 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
index 160b34f..4f19b11 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
index 914c084..56fd726 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
index 478b32a..0e8097f 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
index 5822008..03a5ff1 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
index 9d5c7cd..9696940 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
diff --git a/src/coreclr/tests/src/GC/Features/Pinning/PinningOther/project.json b/src/coreclr/tests/src/GC/Features/Pinning/PinningOther/project.json
deleted file mode 100644 (file)
index 14c11d2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "dependencies": {
-    "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
-    "System.Collections": "4.0.10",
-    "System.Collections.NonGeneric": "4.0.1-beta-23302",
-    "System.Collections.Specialized": "4.0.1-beta-23302",
-    "System.ComponentModel": "4.0.1-beta-23302",
-    "System.Console": "4.0.0-beta-23302",
-    "System.Diagnostics.Process": "4.0.0-beta-23302",
-    "System.Globalization": "4.0.10",
-    "System.Globalization.Calendars": "4.0.0",
-    "System.IO": "4.0.10",
-    "System.IO.FileSystem": "4.0.0",
-    "System.IO.FileSystem.Primitives": "4.0.0",
-    "System.Linq": "4.0.1-beta-23302",
-    "System.Linq.Queryable": "4.0.1-beta-23302",
-    "System.Reflection": "4.0.10",
-    "System.Reflection.Primitives": "4.0.0",
-    "System.Runtime": "4.0.20",
-    "System.Runtime.Extensions": "4.0.10",
-    "System.Runtime.Handles": "4.0.0",
-    "System.Runtime.InteropServices": "4.0.20",
-    "System.Runtime.Loader": "4.0.0-beta-23302",
-    "System.Text.Encoding": "4.0.10",
-    "System.Threading": "4.0.10",
-    "System.Xml.ReaderWriter": "4.0.11-beta-23302",
-    "System.Xml.XDocument": "4.0.11-beta-23302",
-    "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
-  },
-  "frameworks": {
-    "dnxcore50": {}
-  }
-}
diff --git a/src/coreclr/tests/src/GC/Features/SustainedLowLatency/app.config b/src/coreclr/tests/src/GC/Features/SustainedLowLatency/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Features/SustainedLowLatency/scenario.cs b/src/coreclr/tests/src/GC/Features/SustainedLowLatency/scenario.cs
new file mode 100644 (file)
index 0000000..9725b97
--- /dev/null
@@ -0,0 +1,115 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+//This is modeled after a server executing requests
+//which pin some of their newly allocated objects. 
+using System;
+using System.Runtime.InteropServices;
+using System.Diagnostics;
+using System.Threading;
+using System.Runtime;
+
+class request
+{
+    Object[] survivors;
+    GCHandle pin;
+    static Random r = new Random(1234);
+    public request(int alloc_volume, float surv_fraction)
+    {
+        survivors = new Object[1 + (int)(alloc_volume * surv_fraction) / 1000];
+        int i = 0;
+        int volume = 0;
+        //allocate half of the request size. 
+        while (volume < alloc_volume / 2)
+        {
+            int alloc_surv = r.Next(1000, 2000 + 2 * i);
+            
+            int alloc = (int)(alloc_surv / surv_fraction) - alloc_surv;
+            
+            int j = 0;
+            while (j < alloc)
+            {
+                int s = r.Next(100, 200 + 2 * j);
+
+                Object x = new byte[s];
+                j += s;
+            }
+            survivors[i] = new byte[alloc_surv];
+            i++;
+            volume += alloc_surv + alloc;
+        }
+        //allocate one pinned buffer
+        pin = GCHandle.Alloc (new byte [100], GCHandleType.Pinned);
+        //allocate the rest of the request
+        while (volume < alloc_volume)
+        {
+            int alloc_surv = r.Next(1000, 2000 + 2 * i);          
+            int alloc = (int)(alloc_surv / surv_fraction) - alloc_surv;          
+            int j = 0;
+            while (j < alloc)
+            {
+                int s = r.Next(100, 200 + 2 * j);
+
+                Object x = new byte[s];
+                j += s;
+            }
+            survivors[i] = new byte[alloc_surv];
+            i++;
+            volume += alloc_surv + alloc;
+        }
+
+    }
+    public void retire()
+    {
+        pin.Free();
+    }
+
+    static public void Main(String[] args)
+    {
+        int n_requests = 600;
+        int allocation_volume = 100000; // 1 mil
+        float survival_rate = 0.6f;
+        request[] requests = new request[n_requests];
+        int loop = 0;
+        Stopwatch stopwatch = new Stopwatch();
+        stopwatch.Start();
+        double total_elapsed_ms = 0;
+
+        //loop for about 3 min
+        while (total_elapsed_ms < 3 * 60 * 1000)
+        {
+            for (loop = 0; loop < (n_requests * 100); loop++)
+            {
+                int i = r.Next(0, n_requests);
+                if (requests[i] != null)
+                {
+                    requests[i].retire();
+                }
+                requests[i] = new request(allocation_volume, survival_rate);
+                
+            }
+
+            Console.Write(" Cleaning up-------");
+            Console.WriteLine("gen0: {0}, gen1: {1}; gen2: {2}, heap size: {3:N0} bytes",
+                GC.CollectionCount(0),
+                GC.CollectionCount(1),
+                GC.CollectionCount(2),
+                GC.GetTotalMemory(false));
+
+
+            for (loop = 0; loop < n_requests; loop++)
+            {
+                if (requests[loop] != null)
+                {
+                    requests[loop].retire();
+                    requests[loop] = null;
+                }
+            }
+
+            total_elapsed_ms = stopwatch.Elapsed.TotalMilliseconds;
+        }
+    }
+}
+
+
diff --git a/src/coreclr/tests/src/GC/Features/SustainedLowLatency/scenario.csproj b/src/coreclr/tests/src/GC/Features/SustainedLowLatency/scenario.csproj
new file mode 100644 (file)
index 0000000..028c780
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="Scenario.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/SustainedLowLatency/sustainedlowlatency_race.cs b/src/coreclr/tests/src/GC/Features/SustainedLowLatency/sustainedlowlatency_race.cs
new file mode 100644 (file)
index 0000000..20c3bf6
--- /dev/null
@@ -0,0 +1,150 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Runtime;
+
+namespace SustainedLowLatencyTest
+{
+    class SLL
+    {
+        //The test tries to set SustainedLowLatency when a foreground GC is in progress
+        //Regression test for Bug 576224: Race condition using GCSettings.LatencyMode
+        static volatile bool setSSLdone = false;
+        static Int64 iterations = 2000;
+        static bool runForever = false;
+        static bool failed = false;
+
+        static int Main(string[] args)
+        {
+            if (args.Length > 0)
+                iterations = Int64.Parse(args[0]);
+
+            if (iterations == -1)
+                runForever = true;
+            if (runForever)
+                Console.WriteLine("Run until fail");
+            else
+                Console.WriteLine("Run {0} iterations", iterations);
+            Thread t1 = new Thread(SetSLL);
+            Thread t2 = new Thread(Allocate);
+            int numThreads = 100;
+            Thread[] threadArr = new Thread[numThreads];
+            for (int i = 0; i < numThreads; i++)
+            {
+                threadArr[i] = new Thread(AllocateTempObjects);
+                threadArr[i].Start();
+            }
+           
+            t1.Start();
+            t2.Start();
+            
+            t1.Join();
+            t2.Join();
+            for (int i = 0; i < numThreads; i++)
+            {
+                threadArr[i].Join();
+            }
+
+            if (failed)
+            {
+                Console.WriteLine("Test failed");
+                return 1;
+            }
+            Console.WriteLine("Test passed");
+            return 100;
+
+        }
+
+          public static void SetSLL(object threadInfoObj)
+          {
+              System.Threading.Thread.Sleep(200);
+              GCLatencyMode initialMode = GCSettings.LatencyMode;
+              Console.WriteLine("Initial mode is: " + initialMode);
+             
+             Int64 counter = 0;
+              while (!failed &&(runForever || counter<iterations))
+              {
+                  counter++;
+                  GC.Collect(2, GCCollectionMode.Optimized, false);
+
+                  for (int j = 0; j < 100; j++)
+                  {
+                      GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency;
+
+                      GCLatencyMode lm = GCSettings.LatencyMode;
+                      //   Console.WriteLine(lm);
+                      if (lm != GCLatencyMode.SustainedLowLatency)
+                      {
+                          Console.WriteLine("latency mode is {0}; expected GCLatencyMode.SustainedLowLatency", lm);
+                          failed = true;
+                          break;
+                      }
+                      GCSettings.LatencyMode = initialMode;
+                      GCLatencyMode lmOrig = GCSettings.LatencyMode;
+                      if (lmOrig != initialMode)
+                      {
+                          Console.WriteLine("latency mode is {0}; expected {1}", lmOrig, initialMode);
+                          failed = true;
+                          break;
+                      }
+                  }
+             
+                  Thread.Sleep(100);
+              }
+              setSSLdone = true;
+          }
+
+
+          public static void AllocateTempObjects(object threadInfoObj)
+          {
+              int listSize2 = 1000;
+              List<byte[]> tempList = new List<byte[]>();
+              while (!setSSLdone)
+              {
+                  byte[] temp = new byte[20];
+                  for (int i = 0; i < listSize2; i++)
+                  {
+                      tempList.Add(new byte[50]);
+                  }
+                  tempList.Clear();
+              }
+
+          }
+
+          public static void Allocate(object threadInfoObj)
+          {
+              int ListSize = 300;
+              System.Random rnd = new Random(1122);
+             
+              int listSize2 = 1000;
+              List<byte[]> newList = new List<byte[]>(500+1000);
+              
+
+              while (!setSSLdone)
+              {
+                  for (int i = 0; i < ListSize; i++)
+                  {
+                      newList.Add(new byte[85000]);
+                      newList.Add(new byte[200]);
+                      Thread.Sleep(10);
+                  }
+                  for (int i = 0; i < listSize2; i++)
+                  {
+                      newList.Add(new byte[50]);
+                  }
+                  newList.Clear();
+              }
+          }
+
+     
+}
+
+          
+      
+}
diff --git a/src/coreclr/tests/src/GC/Features/SustainedLowLatency/sustainedlowlatency_race.csproj b/src/coreclr/tests/src/GC/Features/SustainedLowLatency/sustainedlowlatency_race.csproj
new file mode 100644 (file)
index 0000000..7048a0c
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="SustainedLowLatency_Race.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Features/SustainedLowLatency/sustainedlowlatency_race_reverse.cs b/src/coreclr/tests/src/GC/Features/SustainedLowLatency/sustainedlowlatency_race_reverse.cs
new file mode 100644 (file)
index 0000000..a21c371
--- /dev/null
@@ -0,0 +1,159 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Runtime;
+
+namespace SustainedLowLatencyTest
+{
+    class SLL
+    {
+        //The test tries to unset SustainedLowLatency when a foreground GC is in progress
+        //Regression test for Bug 576224: Race condition using GCSettings.LatencyMode
+        static volatile bool setSSLdone = false;
+        static Int64 iterations = 2000;
+        static bool runForever = false;
+        static bool failed = false;
+        static GCLatencyMode initialMode;
+
+        static int Main(string[] args)
+        {
+            if (args.Length > 0)
+                iterations = Int64.Parse(args[0]);
+
+            if (iterations == -1)
+                runForever = true;
+            if (runForever)
+                Console.WriteLine("Run until fail");
+            else
+                Console.WriteLine("Run {0} iterations", iterations);
+
+            initialMode = GCSettings.LatencyMode;
+            Console.WriteLine("Initial mode is: " + initialMode);
+            GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency;
+
+            Thread t1 = new Thread(SetSLL);
+            Thread t2 = new Thread(Allocate);
+            int numThreads = 100;
+            Thread[] threadArr = new Thread[numThreads];
+            for (int i = 0; i < numThreads; i++)
+            {
+                threadArr[i] = new Thread(AllocateTempObjects);
+                threadArr[i].Start();
+            }
+           
+            t1.Start();
+            t2.Start();
+            
+            t1.Join();
+            t2.Join();
+            for (int i = 0; i < numThreads; i++)
+            {
+                threadArr[i].Join();
+            }
+
+            if (failed)
+            {
+                Console.WriteLine("Test failed");
+                return 1;
+            }
+            Console.WriteLine("Test passed");
+            return 100;
+
+        }
+
+          public static void SetSLL(object threadInfoObj)
+          {
+              System.Threading.Thread.Sleep(50);
+             
+             Int64 counter = 0;
+              while (!failed &&(runForever || counter<iterations))
+              {
+                  counter++;
+                  GC.Collect(2, GCCollectionMode.Optimized, false);
+
+                  for (int j = 0; j < 100; j++)
+                  {
+                     
+                      GCSettings.LatencyMode = initialMode;
+                      GCLatencyMode lmOrig = GCSettings.LatencyMode;
+                      if (lmOrig != initialMode)
+                      {
+                          Console.WriteLine("latency mode is {0}; expected {1}", lmOrig, initialMode);
+                          failed = true;
+                          break;
+                      }
+                      GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency; ;
+
+                      GCLatencyMode lm = GCSettings.LatencyMode;
+                      //   Console.WriteLine(lm);
+                      if (lm != GCLatencyMode.SustainedLowLatency)
+                      {
+                          Console.WriteLine("latency mode is {0}; expected GCLatencyMode.SustainedLowLatency", lm);
+                          failed = true;
+                          break;
+                      }
+                  }
+             
+                  Thread.Sleep(100);
+              }
+              setSSLdone = true;
+          }
+
+
+          public static void AllocateTempObjects(object threadInfoObj)
+          {
+              int listSize2 = 1000;
+              List<byte[]> tempList = new List<byte[]>();
+              while (!setSSLdone)
+              {
+                  byte[] temp = new byte[20];
+                  for (int i = 0; i < listSize2; i++)
+                  {
+                      tempList.Add(new byte[50]);
+                  }
+                  tempList.Clear();
+              }
+
+          }
+
+          public static void Allocate(object threadInfoObj)
+          {
+              int ListSize = 300;
+              System.Random rnd = new Random(1122);
+             
+              int listSize2 = 1000;
+              List<byte[]> newList = new List<byte[]>(500+1000);
+              
+
+              while (!setSSLdone)
+              {
+                  for (int i = 0; i < ListSize; i++)
+                  {
+                      newList.Add(new byte[85000]);
+                      newList.Add(new byte[200]);
+                      Thread.Sleep(10);
+                  }
+                  for (int i = 0; i < listSize2; i++)
+                  {
+                      newList.Add(new byte[50]);
+                  }
+                  newList.Clear();
+              }
+
+              
+         
+
+          }
+
+     
+}
+
+          
+      
+}
diff --git a/src/coreclr/tests/src/GC/Features/SustainedLowLatency/sustainedlowlatency_race_reverse.csproj b/src/coreclr/tests/src/GC/Features/SustainedLowLatency/sustainedlowlatency_race_reverse.csproj
new file mode 100644 (file)
index 0000000..868ee9c
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="SustainedLowLatency_Race_Reverse.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/LargeMemory/API/gc/app.config b/src/coreclr/tests/src/GC/LargeMemory/API/gc/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/LargeMemory/API/gc/collect.cs b/src/coreclr/tests/src/GC/LargeMemory/API/gc/collect.cs
new file mode 100644 (file)
index 0000000..f39bebb
--- /dev/null
@@ -0,0 +1,82 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+public sealed class CollectTest {
+
+    private int numTests = 0;
+    public uint size = 0;
+
+    private bool collectLargeObject(int gen) {
+        numTests++;
+        LargeObject lo;
+        try {
+            lo = new LargeObject(size, true);
+        } catch (OutOfMemoryException) {
+            Console.WriteLine("Large Memory Machine required");
+            return false;
+        } catch (Exception e) {
+            Console.WriteLine("Unexpected Exception:");
+            Console.WriteLine(e);
+            return false;
+        }
+        lo = null;
+        GC.Collect(gen);
+        GC.WaitForPendingFinalizers();
+        GC.Collect(gen);
+
+        if (LargeObject.FinalizedCount>0) {
+            Console.WriteLine("collectLargeObject {0} passed", gen);
+            return true;
+        }
+
+        Console.WriteLine("collectLargeObject {0} failed", gen);
+        return false;
+    }
+
+    public bool RunTests() {
+        int numPassed = 0;
+
+        if (collectLargeObject(0)) {
+            numPassed++;
+        }
+
+        GC.Collect();
+        GC.WaitForPendingFinalizers();
+        GC.Collect();
+
+        if (collectLargeObject(2)) {
+            numPassed++;
+        }
+
+
+        return (numTests==numPassed);
+    }
+
+    public static int Main(string[] args) {
+
+        uint size = 0;
+        try {
+            size = UInt32.Parse(args[0]);
+        } catch (Exception e) {
+            if ( (e is IndexOutOfRangeException) || (e is FormatException) || (e is OverflowException) ) {
+                Console.WriteLine("args: uint - number of GB to allocate");
+                return 0;
+            }
+            throw;
+        }
+
+        CollectTest test = new CollectTest();
+        test.size = size;
+
+        if (test.RunTests()) {
+            Console.WriteLine("Test passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test failed");
+        return 0;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/LargeMemory/API/gc/collect.csproj b/src/coreclr/tests/src/GC/LargeMemory/API/gc/collect.csproj
new file mode 100644 (file)
index 0000000..e097224
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>2</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="Collect.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="LargeObject.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/LargeMemory/API/gc/getgeneration.cs b/src/coreclr/tests/src/GC/LargeMemory/API/gc/getgeneration.cs
new file mode 100644 (file)
index 0000000..950b24e
--- /dev/null
@@ -0,0 +1,105 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+
+public sealed class GetGenerationTest {
+
+    public uint size = 0;
+    private int numTests=0;
+
+    private bool getGenerationWR() {
+        numTests++;
+        int gen = -1;
+
+        try {
+            gen = GC.GetGeneration(new WeakReference(new LargeObject(size)));
+        } catch (OutOfMemoryException) {
+            Console.WriteLine("Large Memory Machine required");
+            return false;
+        } catch (Exception e) {
+            Console.WriteLine("Unexpected Exception:");
+            Console.WriteLine(e);
+            return false;
+        }
+
+        if (gen==GC.MaxGeneration) {
+            Console.WriteLine("getGenerationWR passed");
+            return true;
+        }
+
+        Console.WriteLine(gen);
+        Console.WriteLine("getGenerationWR failed");
+        return false;
+    }
+
+    private bool getGeneration() {
+        numTests++;
+
+        int gen = -1;
+
+        try {
+            LargeObject lo = new LargeObject(size);
+            gen = GC.GetGeneration(lo);
+
+        } catch (OutOfMemoryException) {
+            Console.WriteLine("Large Memory Machine required");
+            return false;
+        } catch (Exception e) {
+            Console.WriteLine("Unexpected Exception:");
+            Console.WriteLine(e);
+            return false;
+        }
+
+        if (gen==GC.MaxGeneration) {
+            Console.WriteLine("getGeneration passed");
+            return true;
+        }
+
+        Console.WriteLine(gen);
+        Console.WriteLine("getGeneration failed");
+        return false;
+    }
+
+    public bool RunTests() {
+        int numPassed = 0;
+
+        if (getGeneration()) {
+            numPassed++;
+        }
+
+        if (getGenerationWR()) {
+            numPassed++;
+        }
+
+
+        return (numPassed==numTests);
+    }
+
+
+    public static int Main(string[] args) {
+
+        uint size = 0;
+        try {
+            size = UInt32.Parse(args[0]);
+        } catch (Exception e) {
+            if ( (e is IndexOutOfRangeException) || (e is FormatException) || (e is OverflowException) ) {
+                Console.WriteLine("args: uint - number of GB to allocate");
+                return 0;
+            }
+            throw;
+        }
+
+        GetGenerationTest test = new GetGenerationTest();
+        test.size = size;
+        if (test.RunTests()) {
+            Console.WriteLine("Test passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test failed");
+        return 0;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/LargeMemory/API/gc/getgeneration.csproj b/src/coreclr/tests/src/GC/LargeMemory/API/gc/getgeneration.csproj
new file mode 100644 (file)
index 0000000..77b3c63
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>2</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="GetGeneration.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="LargeObject.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/LargeMemory/API/gc/gettotalmemory.cs b/src/coreclr/tests/src/GC/LargeMemory/API/gc/gettotalmemory.cs
new file mode 100644 (file)
index 0000000..8d4eb44
--- /dev/null
@@ -0,0 +1,64 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+public sealed class GetTotalMemoryTest {
+    private uint size = 0;
+    public GetTotalMemoryTest(uint size) {
+        this.size = size;
+    }
+
+
+    public bool RunTests() {
+
+        try {
+            LargeObject lo = new LargeObject(size);
+            long mem  = GC.GetTotalMemory(false);
+            long delta = (long)(size*LargeObject.GB)/(long)10;
+
+            if ( (mem - size*LargeObject.GB)> delta) {
+                Console.WriteLine("{0} {1} {2}", mem, size*LargeObject.GB, delta);
+                return false;
+            }
+
+            GC.KeepAlive(lo);
+
+        } catch (OutOfMemoryException) {
+            Console.WriteLine("Large Memory Machine required");
+            return false;
+        } catch (Exception e) {
+            Console.WriteLine("Unexpected Exception:");
+            Console.WriteLine(e);
+            return false;
+        }
+
+        return true;
+
+    }
+
+    public static int Main(string[] args) {
+
+        uint size = 0;
+        try {
+            size = UInt32.Parse(args[0]);
+        } catch (Exception e) {
+            if ( (e is IndexOutOfRangeException) || (e is FormatException) || (e is OverflowException) ) {
+                Console.WriteLine("args: uint - number of GB to allocate");
+                return 0;
+            }
+            throw;
+        }
+
+
+        GetTotalMemoryTest test = new GetTotalMemoryTest(size);
+        if (test.RunTests()) {
+            Console.WriteLine("Test passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test failed");
+        return 0;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/LargeMemory/API/gc/gettotalmemory.csproj b/src/coreclr/tests/src/GC/LargeMemory/API/gc/gettotalmemory.csproj
new file mode 100644 (file)
index 0000000..e3bd5d2
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>2</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="GetTotalMemory.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="LargeObject.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/LargeMemory/API/gc/keepalive.cs b/src/coreclr/tests/src/GC/LargeMemory/API/gc/keepalive.cs
new file mode 100644 (file)
index 0000000..a7bcd93
--- /dev/null
@@ -0,0 +1,65 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+public sealed class KeepAliveTest {
+
+    private uint size = 0;
+
+    public KeepAliveTest(uint size) {
+        this.size = size;
+    }
+
+    public bool RunTests() {
+
+       try {
+            LargeObject lo = new LargeObject(size);
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+
+            if (lo == null)
+                return false;
+            GC.KeepAlive(lo);
+
+        } catch (OutOfMemoryException) {
+            Console.WriteLine("Large Memory Machine required");
+            return false;
+        } catch (Exception e) {
+            Console.WriteLine("Unexpected Exception:");
+            Console.WriteLine(e);
+            return false;
+        }
+
+        return true;
+    }
+
+
+    public static int Main(string[] args) {
+
+        uint size = 0;
+        try {
+           size = UInt32.Parse(args[0]);
+        } catch (Exception e) {
+           if ( (e is IndexOutOfRangeException) || (e is FormatException) || (e is OverflowException) ) {
+               Console.WriteLine("args: uint - number of GB to allocate");
+               return 0;
+           }
+           throw;
+        }
+
+
+        KeepAliveTest test = new KeepAliveTest(size);
+
+        if (test.RunTests()) {
+            Console.WriteLine("Test passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test failed");
+        return 0;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/LargeMemory/API/gc/keepalive.csproj b/src/coreclr/tests/src/GC/LargeMemory/API/gc/keepalive.csproj
new file mode 100644 (file)
index 0000000..afcdaa2
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>2</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="KeepAlive.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="LargeObject.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/LargeMemory/API/gc/largeobject.cs b/src/coreclr/tests/src/GC/LargeMemory/API/gc/largeobject.cs
new file mode 100644 (file)
index 0000000..6d7bef3
--- /dev/null
@@ -0,0 +1,50 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+//[Serializable()]
+public sealed class LargeObject {
+
+    private byte[][] data;
+    private uint sizeInGB;
+    private LargeObject next;
+    public static int FinalizedCount = 0;
+
+    public const long GB = 1024*1024*1024;
+
+    public LargeObject(uint sizeInGB):this(sizeInGB, false)
+    {
+    }
+
+    public LargeObject(uint sizeInGB, bool finalize) {
+        this.sizeInGB = sizeInGB;
+
+        if (!finalize) {
+            GC.SuppressFinalize(this);
+        }
+
+        data = new byte[sizeInGB][];
+        for (int i=0; i<sizeInGB; i++) {
+            data[i] = new byte[GB];
+        }
+    }
+
+    ~LargeObject() {
+        Console.WriteLine("Finalized");
+        FinalizedCount++;
+    }
+
+    public long Size {
+        get {
+            return sizeInGB*GB;
+        }
+    }
+
+    public LargeObject Next {
+        get { return next; }
+        set { next = value; }
+    }
+
+}
diff --git a/src/coreclr/tests/src/GC/LargeMemory/API/gc/largeobject.csproj b/src/coreclr/tests/src/GC/LargeMemory/API/gc/largeobject.csproj
new file mode 100644 (file)
index 0000000..519a281
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestKind>BuildOnly</CLRTestKind>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="LargeObject.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/LargeMemory/API/gc/reregisterforfinalize.cs b/src/coreclr/tests/src/GC/LargeMemory/API/gc/reregisterforfinalize.cs
new file mode 100644 (file)
index 0000000..8690ee9
--- /dev/null
@@ -0,0 +1,62 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+public sealed class ReRegisterForFinalizeTest {
+
+    private uint size = 0;
+
+    public ReRegisterForFinalizeTest(uint size ) {
+        this.size = size;
+    }
+
+
+    public bool RunTests() {
+
+        LargeObject lo;
+        try {
+            lo = new LargeObject(size, true);
+            GC.ReRegisterForFinalize(lo);
+        } catch (OutOfMemoryException) {
+            Console.WriteLine("Large Memory Machine required");
+            return false;
+        } catch (Exception e) {
+            Console.WriteLine("Unexpected Exception:");
+            Console.WriteLine(e);
+            return false;
+        }
+        lo = null;
+        GC.Collect();
+        GC.WaitForPendingFinalizers();
+        GC.Collect();
+
+        return (LargeObject.FinalizedCount==2);
+    }
+
+    public static int Main(string[] args) {
+
+        uint size = 0;
+        try {
+           size = UInt32.Parse(args[0]);
+        } catch (Exception e) {
+           if ( (e is IndexOutOfRangeException) || (e is FormatException) || (e is OverflowException) ) {
+               Console.WriteLine("args: uint - number of GB to allocate");
+               return 0;
+           }
+           throw;
+        }
+
+
+        ReRegisterForFinalizeTest test = new ReRegisterForFinalizeTest(size);
+
+        if (test.RunTests()) {
+            Console.WriteLine("Test passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test failed");
+        return 0;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/LargeMemory/API/gc/reregisterforfinalize.csproj b/src/coreclr/tests/src/GC/LargeMemory/API/gc/reregisterforfinalize.csproj
new file mode 100644 (file)
index 0000000..28e8859
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>2</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="ReRegisterForFinalize.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="LargeObject.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/LargeMemory/API/gc/suppressfinalize.cs b/src/coreclr/tests/src/GC/LargeMemory/API/gc/suppressfinalize.cs
new file mode 100644 (file)
index 0000000..d3ec74d
--- /dev/null
@@ -0,0 +1,62 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+public sealed class SuppressFinalizeTest {
+
+    private uint size = 0;
+
+    public SuppressFinalizeTest(uint size ) {
+        this.size = size;
+    }
+
+
+    public bool RunTests() {
+
+        LargeObject lo;
+        try {
+            lo = new LargeObject(size, true);
+            GC.SuppressFinalize(lo);
+        } catch (OutOfMemoryException) {
+            Console.WriteLine("Large Memory Machine required");
+            return false;
+        } catch (Exception e) {
+            Console.WriteLine("Unexpected Exception:");
+            Console.WriteLine(e);
+            return false;
+        }
+        lo = null;
+        GC.Collect();
+        GC.WaitForPendingFinalizers();
+        GC.Collect();
+
+        return (LargeObject.FinalizedCount==0);
+    }
+
+    public static int Main(string[] args) {
+
+        uint size = 0;
+        try {
+           size = UInt32.Parse(args[0]);
+        } catch (Exception e) {
+           if ( (e is IndexOutOfRangeException) || (e is FormatException) || (e is OverflowException) ) {
+               Console.WriteLine("args: uint - number of GB to allocate");
+               return 0;
+           }
+           throw;
+        }
+
+
+        SuppressFinalizeTest test = new SuppressFinalizeTest(size);
+
+        if (test.RunTests()) {
+            Console.WriteLine("Test passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test failed");
+        return 0;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/LargeMemory/API/gc/suppressfinalize.csproj b/src/coreclr/tests/src/GC/LargeMemory/API/gc/suppressfinalize.csproj
new file mode 100644 (file)
index 0000000..c083450
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>2</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="SuppressFinalize.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="LargeObject.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/LargeMemory/Allocation/app.config b/src/coreclr/tests/src/GC/LargeMemory/Allocation/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/LargeMemory/Allocation/finalizertest.cs b/src/coreclr/tests/src/GC/LargeMemory/Allocation/finalizertest.cs
new file mode 100644 (file)
index 0000000..66ac448
--- /dev/null
@@ -0,0 +1,171 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+// a large object that resurrects itself
+public sealed class LargeObject2 {
+
+    private byte[][] data;
+
+    public const long GB = 1024*1024*1024;
+
+    public LargeObject2(uint sizeInGB)
+    {
+        data = new byte[sizeInGB][];
+        for (int i=0; i<sizeInGB; i++) {
+            data[i] = new byte[GB];
+        }
+
+    }
+
+    ~LargeObject2() {
+        FinalizerTest.LO2 = this;
+    }
+
+}
+
+// allocates a large object on the finalizer thread
+public sealed class FinalizerObject {
+    uint size = 0;
+
+    public FinalizerObject(uint sizeInGB)
+    {
+        size = sizeInGB;
+    }
+
+    ~FinalizerObject() {
+
+        LargeObject lo =null;
+
+        try {
+            lo = new LargeObject(size);
+        } catch (OutOfMemoryException) {
+            Console.WriteLine("OOM");
+            return;
+        } catch (Exception e) {
+            Console.WriteLine("Unexpected Exception");
+            Console.WriteLine(e);
+            return;
+        }
+
+        if (lo!=null)
+            FinalizerTest.ObjectSize = lo.Size;
+        GC.KeepAlive(lo);
+    }
+}
+
+
+public sealed class FinalizerTest {
+
+    public static LargeObject2 LO2 = null;
+    public static long ObjectSize = 0;
+
+    private uint size = 0;
+    private int numTests = 0;
+
+
+    public FinalizerTest(uint size) {
+        this.size = size;
+    }
+
+    bool ressurectionTest() {
+        numTests++;
+
+        try {
+            new LargeObject2(size);
+        } catch (OutOfMemoryException) {
+            Console.WriteLine("Large Memory Machine required");
+            return false;
+        } catch (Exception e) {
+            Console.WriteLine("Unexpected Exception");
+            Console.WriteLine(e);
+            return false;
+        }
+
+        GC.Collect();
+        GC.WaitForPendingFinalizers();
+        GC.Collect();
+
+        if (LO2 != null) {
+            Console.WriteLine("ressurectionTest passed");
+            LO2 = null;
+            return true;
+        }
+        Console.WriteLine("ressurectionTest failed");
+        return false;
+
+    }
+
+
+    bool allocateInFinalizerTest() {
+        numTests++;
+
+        try {
+            new FinalizerObject(size);
+        } catch (OutOfMemoryException) {
+            Console.WriteLine("Large Memory Machine required");
+            return false;
+        } catch (Exception e) {
+            Console.WriteLine("Unexpected Exception");
+            Console.WriteLine(e);
+            return false;
+        }
+
+        GC.Collect();
+        GC.WaitForPendingFinalizers();
+        GC.Collect();
+
+        if (ObjectSize == size*LargeObject.GB) {
+            Console.WriteLine("allocateInFinalizerTest passed");
+            return true;
+        }
+        Console.WriteLine("{0} {1}", ObjectSize, size*LargeObject.GB);
+        Console.WriteLine("allocateInFinalizerTest failed");
+        return false;
+
+    }
+
+    public bool RunTests() {
+
+        int numPassed = 0;
+
+        if (allocateInFinalizerTest() ) {
+            numPassed++;
+        }
+
+        if (ressurectionTest() ) {
+            numPassed++;
+        }
+
+        return (numTests==numPassed);
+    }
+
+
+    public static int Main(string[] args) {
+
+        uint size = 0;
+        try {
+            size = UInt32.Parse(args[0]);
+        } catch (Exception e) {
+            if ( (e is IndexOutOfRangeException) || (e is FormatException) || (e is OverflowException) ) {
+                Console.WriteLine("args: uint - number of GB to allocate");
+                return 0;
+            }
+            throw;
+        }
+
+        FinalizerTest test = new FinalizerTest(size);
+
+
+        if (test.RunTests()) {
+            Console.WriteLine("Test passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test failed");
+        return 0;
+    }
+}
+
diff --git a/src/coreclr/tests/src/GC/LargeMemory/Allocation/finalizertest.csproj b/src/coreclr/tests/src/GC/LargeMemory/Allocation/finalizertest.csproj
new file mode 100644 (file)
index 0000000..328fc7f
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>2</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="FinalizerTest.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="LargeObject.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/LargeMemory/Allocation/largeexceptiontest.cs b/src/coreclr/tests/src/GC/LargeMemory/Allocation/largeexceptiontest.cs
new file mode 100644 (file)
index 0000000..9bb926c
--- /dev/null
@@ -0,0 +1,69 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+public sealed class LargeException : Exception
+{
+// disabling unused variable warning
+#pragma warning disable 0414
+    LargeObject lo;
+#pragma warning restore 0414
+
+    public LargeException(uint size) {
+        lo = new LargeObject(size);
+    }
+}
+
+
+public sealed class LargeExceptionTest {
+
+    private uint size = 0;
+    public LargeExceptionTest(uint size) {
+        this.size = size;
+    }
+
+    public bool RunTests() {
+
+        try {
+            throw new LargeException(size);
+        } catch (OutOfMemoryException) {
+            Console.WriteLine("Large Memory Machine required");
+            return false;
+        } catch (LargeException) {
+            return true;
+        } catch (Exception e) {
+            Console.WriteLine("Unexpected Exception");
+            Console.WriteLine(e);
+            return false;
+        }
+
+    }
+
+    public static int Main(string[] args) {
+
+        uint size = 0;
+        try {
+            size = UInt32.Parse(args[0]);
+        } catch (Exception e) {
+            if ( (e is IndexOutOfRangeException) || (e is FormatException) || (e is OverflowException) ) {
+                Console.WriteLine("args: uint - number of GB to allocate");
+                return 0;
+            }
+            throw;
+        }
+
+        LargeExceptionTest test = new LargeExceptionTest(size);
+
+
+        if (test.RunTests()) {
+            Console.WriteLine("Test passed");
+            return 100;
+        }
+
+        Console.WriteLine("Test failed");
+        return 0;
+    }
+}
+
diff --git a/src/coreclr/tests/src/GC/LargeMemory/Allocation/largeexceptiontest.csproj b/src/coreclr/tests/src/GC/LargeMemory/Allocation/largeexceptiontest.csproj
new file mode 100644 (file)
index 0000000..a865530
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>2</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="LargeExceptionTest.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="LargeObject.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/LargeMemory/Allocation/largeobject.cs b/src/coreclr/tests/src/GC/LargeMemory/Allocation/largeobject.cs
new file mode 100644 (file)
index 0000000..6d7bef3
--- /dev/null
@@ -0,0 +1,50 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+//[Serializable()]
+public sealed class LargeObject {
+
+    private byte[][] data;
+    private uint sizeInGB;
+    private LargeObject next;
+    public static int FinalizedCount = 0;
+
+    public const long GB = 1024*1024*1024;
+
+    public LargeObject(uint sizeInGB):this(sizeInGB, false)
+    {
+    }
+
+    public LargeObject(uint sizeInGB, bool finalize) {
+        this.sizeInGB = sizeInGB;
+
+        if (!finalize) {
+            GC.SuppressFinalize(this);
+        }
+
+        data = new byte[sizeInGB][];
+        for (int i=0; i<sizeInGB; i++) {
+            data[i] = new byte[GB];
+        }
+    }
+
+    ~LargeObject() {
+        Console.WriteLine("Finalized");
+        FinalizedCount++;
+    }
+
+    public long Size {
+        get {
+            return sizeInGB*GB;
+        }
+    }
+
+    public LargeObject Next {
+        get { return next; }
+        set { next = value; }
+    }
+
+}
diff --git a/src/coreclr/tests/src/GC/LargeMemory/Allocation/largeobject.csproj b/src/coreclr/tests/src/GC/LargeMemory/Allocation/largeobject.csproj
new file mode 100644 (file)
index 0000000..519a281
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestKind>BuildOnly</CLRTestKind>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="LargeObject.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/LargeMemory/Regressions/app.config b/src/coreclr/tests/src/GC/LargeMemory/Regressions/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/LargeMemory/Regressions/largearraytest.cs b/src/coreclr/tests/src/GC/LargeMemory/Regressions/largearraytest.cs
new file mode 100644 (file)
index 0000000..f5e0385
--- /dev/null
@@ -0,0 +1,38 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/* NAME:        LargeArrayTest
+ * DATE:        2004-03-02
+ * DESCRIPTION: creates arrays of size Int32.MaxValue through Int32.MaxValue-100 inclusive
+ */
+
+using System;
+
+public class LargeArrayTest {
+
+    public static int Main(string[] args) {
+
+        for (int i=0; i<= 100; i++) {
+            try {
+                Console.Write("now try Int32.MaxValue-{0}: ", i);
+                Array a = Array.CreateInstance((new byte().GetType()), Int32.MaxValue-i);
+                Console.WriteLine(a.Length);
+                a = null;
+            } catch (OutOfMemoryException e) {
+                Console.WriteLine();
+                Console.WriteLine(e.Message);
+            } catch (Exception e) {
+                Console.WriteLine();
+                Console.WriteLine("Unexpected Exception!");
+                Console.WriteLine(e);
+                Console.WriteLine("Test Failed!");
+                return 0;
+            }
+        }
+
+        Console.WriteLine("Test Passed!");
+        return 100;
+    }
+
+}
diff --git a/src/coreclr/tests/src/GC/LargeMemory/Regressions/largearraytest.csproj b/src/coreclr/tests/src/GC/LargeMemory/Regressions/largearraytest.csproj
new file mode 100644 (file)
index 0000000..2b9dd89
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="LargeArrayTest.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/LargeMemory/Regressions/pressureoverflow.cs b/src/coreclr/tests/src/GC/LargeMemory/Regressions/pressureoverflow.cs
new file mode 100644 (file)
index 0000000..2316989
--- /dev/null
@@ -0,0 +1,91 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/* NAME: PressureOverflow
+ * DATE: 2004-03-22
+ */
+
+using System;
+
+public class PressureOverflow {
+
+    int numTests = 0;
+
+    // memory pressure should overflow when increased beyond ulong.MaxInt
+    public bool AddTest() {
+        numTests++;
+        bool retVal = false;
+
+        for (int i=0; i<3; i++) {
+            try {
+                GC.AddMemoryPressure(Int64.MaxValue);
+                retVal = true;
+            } catch (ArgumentOutOfRangeException) {
+                Console.WriteLine("This test is for 64-bit only!");
+                retVal = true;
+                break;
+            } catch (Exception e) {
+                Console.WriteLine("Caught unexpected exception at {0}", i);
+                Console.WriteLine(e);
+                retVal = false;
+                break;
+            }
+
+        }
+
+        return retVal;
+
+    }
+
+    // memory pressure should underflow when decreased beyond ulong.MaxInt
+    public bool RemoveTest() {
+        numTests++;
+        bool retVal = false;
+
+        for (int i=0; i<3; i++) {
+            try {
+                GC.RemoveMemoryPressure(Int64.MaxValue);
+                retVal = true;
+            } catch (ArgumentOutOfRangeException) {
+                Console.WriteLine("This test is for 64-bit only!");
+                retVal = true;
+                break;
+            } catch (Exception e) {
+                Console.WriteLine("Caught unexpected exception at {0}", i);
+                Console.WriteLine(e);
+                retVal = false;
+                break;
+            }
+        }
+        return retVal;
+
+    }
+
+    public bool RunTest() {
+
+        int numPassed = 0;
+
+        if (AddTest())
+            numPassed++;
+        if (RemoveTest())
+            numPassed++;
+
+        return (numPassed == numTests);
+    }
+
+
+    public static int Main() {
+
+            PressureOverflow a = new PressureOverflow();
+
+            if (a.RunTest()) {
+                Console.WriteLine("Test Passed!");
+                return 100;
+            }
+            Console.WriteLine("Test Failed!");
+            return 1;
+
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/LargeMemory/Regressions/pressureoverflow.csproj b/src/coreclr/tests/src/GC/LargeMemory/Regressions/pressureoverflow.csproj
new file mode 100644 (file)
index 0000000..7381bf0
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="PressureOverflow.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/M10/RefCrossTHDs/app.config b/src/coreclr/tests/src/GC/M10/RefCrossTHDs/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/M10/RefCrossTHDs/refcrossthds.cs b/src/coreclr/tests/src/GC/M10/RefCrossTHDs/refcrossthds.cs
new file mode 100644 (file)
index 0000000..c5061b9
--- /dev/null
@@ -0,0 +1,172 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.IO;
+
+namespace CrossThds
+{
+        using System.Reflection;
+       using System.Threading;
+
+       class Node
+       {
+               int [] mem;
+               public Node Next;
+               public Node Last;
+               public Node()
+               {
+                       mem= new int[256]; //1K
+                       mem[0] = 0;
+                       mem[255] = 256;
+                       Next = null;
+                       Last = null;
+               }
+       }
+
+       class RefCrossThds
+       {
+               static Object [] ObjAry = new Object[2];
+
+               public RefCrossThds()
+               {
+// console synchronization Console.SetOut(TextWriter.Synchronized(Console.Out));
+               }
+
+        private static void ThreadAbort(Thread thread)
+        {
+            MethodInfo abort = null;
+            foreach(MethodInfo m in thread.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance))
+            {
+                if (m.Name.Equals("AbortInternal") && m.GetParameters().Length == 0) abort = m;
+            }
+            if (abort == null) {
+                throw new Exception("Failed to get Thread.Abort method");
+            }
+            abort.Invoke(thread, new object[0]);
+         }
+
+               public static int Main(String [] str)
+               {
+                       Console.Out.WriteLine( "RefCrossThds");
+                       Console.Out.WriteLine( "Should exit with a 100");
+                       // console synchronization Console.SetOut(TextWriter.Synchronized(Console.Out));
+                       Thread [] thd = new Thread[2];
+                       RefCrossThds mainobj = new RefCrossThds();
+
+                       for(int i=0; i< 2; i++)
+                       {
+                               ObjAry[i] = new Node();
+                       }
+
+                       for( int i=0; i<2; i++ )
+                       {
+                               thd[i] = new Thread( new ThreadStart( mainobj.RunThread ) );
+                               thd[i].Start();
+                       }
+                       Thread.Sleep(5000);
+                       for(int i=0; i< 2; i++)
+                       {
+                               ThreadAbort(thd[i]);
+//                             thd[i].Join();
+                       }
+                       Console.Out.WriteLine( "Test Passed");
+                       return 100;
+               }
+
+               void RunThread()
+               {
+                       Random Ran;
+                       Ran = new Random();
+                       while(true)
+                       {
+                               int iRand = Ran.Next(0, 512);
+                               if( iRand%2 == 0 )
+                                   lock (ObjAry[0]) {DoDoubLink(ObjAry[0], iRand/2);}
+                               else
+                                       lock (ObjAry[1]) {DoSingLink(ObjAry[1], iRand/2+1);}
+                       }
+               }
+
+       //**create or delete a node from double link list.                                                      **/
+       //**If the passin index is smaller than the length of the double link list, **/
+       //**delete the object at the index, otherwise add a new object to the list.     **/
+               static
+               void DoDoubLink(Object head, int index)
+               {
+                       int depth = 0;
+
+                       Node Current = (Node)head;
+                       bool bAdd;
+                       while( true )
+                       {
+                               if( Current.Next == null)
+                               {
+                                       bAdd = true;
+                                       break;
+                               }
+                               else
+                               {
+                                       if( index == depth )
+                                       {
+                                               bAdd = false;
+                                               break;
+                                       }
+                                       depth++;
+                               }
+                               Current = Current.Next;
+                       }
+
+                       if( bAdd )
+                       {
+                               Current.Next = new Node();
+                               Current.Next.Last = Current;
+                       }
+                       else
+                       {
+                               Current.Last = Current.Next;
+                               Current.Next.Last = Current.Last;
+                       }
+               }
+
+       //**create or delete a node from single link list.                                                      **/
+       //**If the passin index is smaller than the length of the single link list, **/
+       //**delete the object at the index, otherwise add a new object to the list.     **/
+               static
+               void DoSingLink(Object head, int index)
+               {
+                       int depth = 0;
+                       Node Current = (Node)head;
+                       bool bAdd;
+                       while( true )
+                       {
+                               if( Current.Next == null)
+                               {
+                                       bAdd = true;
+                                       break;
+                               }
+                               else
+                               {
+                                       if( index == depth )
+                                       {
+                                               bAdd = false;
+                                               break;
+                                       }
+                                       depth++;
+                               }
+                               Current = Current.Next;
+                       }
+
+                       if( bAdd )
+                       {
+                               Current.Next = new Node();
+                       }
+                       else
+                       {
+                               Current.Last = Current.Next;
+                       }
+               }
+       }
+
+}//end of namespace
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/M10/RefCrossTHDs/refcrossthds.csproj b/src/coreclr/tests/src/GC/M10/RefCrossTHDs/refcrossthds.csproj
new file mode 100644 (file)
index 0000000..347bae2
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="RefCrossThds.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Regressions/dev10bugs/536168/536168.cs b/src/coreclr/tests/src/GC/Regressions/dev10bugs/536168/536168.cs
new file mode 100644 (file)
index 0000000..fc5f2f9
--- /dev/null
@@ -0,0 +1,65 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+using System.Threading;
+
+public class Program
+{
+    private static volatile int g_completed = 0;
+    private static int g_interations = 5000000;
+
+    public void Test()
+    {
+
+        int?[] values = new int?[128 * 1024];
+
+        for (int i = 0; i < values.Length; i++) values[i] = 5;
+
+        for (int i = 0; i < values.Length; i++)
+        {
+
+            values[i] = (int)0x42424242;
+
+            if (IsNull(values[i])) Console.WriteLine("Null found.");
+
+        }
+
+        System.Threading.Interlocked.Increment(ref g_completed);
+    }
+
+    public virtual bool IsNull(int? x)
+    {
+
+        return x == null;
+
+    }
+
+    public static int Main()
+    {
+
+        Program p = new Program();
+
+        for (int i = 0; i < g_interations; i++)
+        {
+
+            ThreadPool.QueueUserWorkItem(o => p.Test());
+
+        }
+
+        while (true)
+        {
+            GC.Collect();
+
+            Thread.Sleep(1);
+
+            if (g_completed >= g_interations) break; 
+        }
+
+        return 100;
+
+    }
+
+}
diff --git a/src/coreclr/tests/src/GC/Regressions/dev10bugs/536168/536168.csproj b/src/coreclr/tests/src/GC/Regressions/dev10bugs/536168/536168.csproj
new file mode 100644 (file)
index 0000000..f2b5942
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="536168.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Regressions/dev10bugs/536168/app.config b/src/coreclr/tests/src/GC/Regressions/dev10bugs/536168/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
index 2ba6e65..dda7cd6 100644 (file)
@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
-//VSWhidbey bug# 149926 - OutOfMemoryException allocating a byte array
-
 using System;
 
 public class ArrayOOM
index 1b4f144..669fa78 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta1/149926/project.json b/src/coreclr/tests/src/GC/Regressions/v2.0-beta1/149926/project.json
deleted file mode 100644 (file)
index 14c11d2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "dependencies": {
-    "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
-    "System.Collections": "4.0.10",
-    "System.Collections.NonGeneric": "4.0.1-beta-23302",
-    "System.Collections.Specialized": "4.0.1-beta-23302",
-    "System.ComponentModel": "4.0.1-beta-23302",
-    "System.Console": "4.0.0-beta-23302",
-    "System.Diagnostics.Process": "4.0.0-beta-23302",
-    "System.Globalization": "4.0.10",
-    "System.Globalization.Calendars": "4.0.0",
-    "System.IO": "4.0.10",
-    "System.IO.FileSystem": "4.0.0",
-    "System.IO.FileSystem.Primitives": "4.0.0",
-    "System.Linq": "4.0.1-beta-23302",
-    "System.Linq.Queryable": "4.0.1-beta-23302",
-    "System.Reflection": "4.0.10",
-    "System.Reflection.Primitives": "4.0.0",
-    "System.Runtime": "4.0.20",
-    "System.Runtime.Extensions": "4.0.10",
-    "System.Runtime.Handles": "4.0.0",
-    "System.Runtime.InteropServices": "4.0.20",
-    "System.Runtime.Loader": "4.0.0-beta-23302",
-    "System.Text.Encoding": "4.0.10",
-    "System.Threading": "4.0.10",
-    "System.Xml.ReaderWriter": "4.0.11-beta-23302",
-    "System.Xml.XDocument": "4.0.11-beta-23302",
-    "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
-  },
-  "frameworks": {
-    "dnxcore50": {}
-  }
-}
index ad4ab20..a8ca213 100644 (file)
@@ -3,8 +3,6 @@
 // See the LICENSE file in the project root for more information.
 
 /*
- *  SDET:           clyon
- *  BUG:            289745 (wks), 302560 (svr)
  *  DESCRIPTION:    GC clobbers read-only frozen segments
  *  NOTE:           if unable to repro, tweak the array lengths depending on the amount of physical ram in your machine
  */
index b639922..5e17987 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
index b639922..5e17987 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta1/289745/project.json b/src/coreclr/tests/src/GC/Regressions/v2.0-beta1/289745/project.json
deleted file mode 100644 (file)
index 14c11d2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "dependencies": {
-    "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
-    "System.Collections": "4.0.10",
-    "System.Collections.NonGeneric": "4.0.1-beta-23302",
-    "System.Collections.Specialized": "4.0.1-beta-23302",
-    "System.ComponentModel": "4.0.1-beta-23302",
-    "System.Console": "4.0.0-beta-23302",
-    "System.Diagnostics.Process": "4.0.0-beta-23302",
-    "System.Globalization": "4.0.10",
-    "System.Globalization.Calendars": "4.0.0",
-    "System.IO": "4.0.10",
-    "System.IO.FileSystem": "4.0.0",
-    "System.IO.FileSystem.Primitives": "4.0.0",
-    "System.Linq": "4.0.1-beta-23302",
-    "System.Linq.Queryable": "4.0.1-beta-23302",
-    "System.Reflection": "4.0.10",
-    "System.Reflection.Primitives": "4.0.0",
-    "System.Runtime": "4.0.20",
-    "System.Runtime.Extensions": "4.0.10",
-    "System.Runtime.Handles": "4.0.0",
-    "System.Runtime.InteropServices": "4.0.20",
-    "System.Runtime.Loader": "4.0.0-beta-23302",
-    "System.Text.Encoding": "4.0.10",
-    "System.Threading": "4.0.10",
-    "System.Xml.ReaderWriter": "4.0.11-beta-23302",
-    "System.Xml.XDocument": "4.0.11-beta-23302",
-    "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
-  },
-  "frameworks": {
-    "dnxcore50": {}
-  }
-}
index 093d14f..3e4639e 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/426480/project.json b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/426480/project.json
deleted file mode 100644 (file)
index 14c11d2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "dependencies": {
-    "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
-    "System.Collections": "4.0.10",
-    "System.Collections.NonGeneric": "4.0.1-beta-23302",
-    "System.Collections.Specialized": "4.0.1-beta-23302",
-    "System.ComponentModel": "4.0.1-beta-23302",
-    "System.Console": "4.0.0-beta-23302",
-    "System.Diagnostics.Process": "4.0.0-beta-23302",
-    "System.Globalization": "4.0.10",
-    "System.Globalization.Calendars": "4.0.0",
-    "System.IO": "4.0.10",
-    "System.IO.FileSystem": "4.0.0",
-    "System.IO.FileSystem.Primitives": "4.0.0",
-    "System.Linq": "4.0.1-beta-23302",
-    "System.Linq.Queryable": "4.0.1-beta-23302",
-    "System.Reflection": "4.0.10",
-    "System.Reflection.Primitives": "4.0.0",
-    "System.Runtime": "4.0.20",
-    "System.Runtime.Extensions": "4.0.10",
-    "System.Runtime.Handles": "4.0.0",
-    "System.Runtime.InteropServices": "4.0.20",
-    "System.Runtime.Loader": "4.0.0-beta-23302",
-    "System.Text.Encoding": "4.0.10",
-    "System.Threading": "4.0.10",
-    "System.Xml.ReaderWriter": "4.0.11-beta-23302",
-    "System.Xml.XDocument": "4.0.11-beta-23302",
-    "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
-  },
-  "frameworks": {
-    "dnxcore50": {}
-  }
-}
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/437657/437657.cs b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/437657/437657.cs
new file mode 100644 (file)
index 0000000..44c8f9e
--- /dev/null
@@ -0,0 +1,333 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*
+a good test would be to create a big object with very sparse pointers embedded.
+For example, you can create an array of value types and each value type has
+mostly integers, say 100 integers and only 2 pointers. When we push stuff onto
+the mark stack we first push all the 1st level sub pointers onto the stack at
+once. So you want to create an object with that big array embedded in it. This
+is a test program that I used to test the change but you'd have to modify it a
+little bit to see a noticable difference. But it's good enough to illustrate
+the point.
+*/
+
+using System;
+using System.Runtime;
+using System.Runtime.InteropServices;
+
+public class A
+{
+    public int a;
+    public A()
+    {
+        a = 1;
+    }
+}
+
+public class B
+{
+    public int b;
+    public B()
+    {
+        b = 2;
+    }
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public struct C
+{
+
+    int i00;
+    int i01;
+    int i02;
+    int i03;
+    int i04;
+    int i05;
+    int i06;
+    int i07;
+    int i08;
+    int i09;
+    int i10;
+    int i11;
+    int i12;
+    int i13;
+    int i14;
+    int i15;
+    int i16;
+    int i17;
+    int i18;
+    int i19;
+    int i20;
+    int i21;
+    int i22;
+    int i23;
+    int i24;
+    int i25;
+    int i26;
+    int i27;
+    int i28;
+    int i29;
+    int i30;
+    int i31;
+    int i32;
+    int i33;
+
+    public A t1;
+
+    int i34;
+    int i35;
+    int i36;
+    int i37;
+    int i38;
+    int i39;
+    int i40;
+    int i41;
+    int i42;
+    int i43;
+    int i44;
+    int i45;
+    int i46;
+    int i47;
+    int i48;
+    int i49;
+    int i50;
+    int i51;
+    int i52;
+    int i53;
+    int i54;
+    int i55;
+    int i56;
+    int i57;
+    int i58;
+    int i59;
+    int i60;
+    int i61;
+    int i62;
+    int i63;
+    int i64;
+    int i65;
+    int i66;
+
+    public B t2;
+
+    int i67;
+    int i68;
+    int i69;
+    int i70;
+    int i71;
+    int i72;
+    int i73;
+    int i74;
+    int i75;
+    int i76;
+    int i77;
+    int i78;
+    int i79;
+    int i80;
+    int i81;
+    int i82;
+    int i83;
+    int i84;
+    int i85;
+    int i86;
+    int i87;
+    int i88;
+    int i89;
+    int i90;
+    int i91;
+    int i92;
+    int i93;
+    int i94;
+    int i95;
+    int i96;
+    int i97;
+    int i98;
+    int i99;
+    int j00;
+    int j01;
+    int j02;
+    int j03;
+    int j04;
+    int j05;
+    int j06;
+    int j07;
+    int j08;
+    int j09;
+    int j10;
+    int j11;
+    int j12;
+    int j13;
+    int j14;
+    int j15;
+    int j16;
+    int j17;
+    int j18;
+    int j19;
+    int j20;
+    int j21;
+    int j22;
+    int j23;
+    int j24;
+    int j25;
+    int j26;
+    int j27;
+    int j28;
+    int j29;
+    int j30;
+    int j31;
+    int j32;
+    int j33;
+
+    public A t3;
+
+    int j34;
+    int j35;
+    int j36;
+    int j37;
+    int j38;
+    int j39;
+    int j40;
+    int j41;
+    int j42;
+    int j43;
+    int j44;
+    int j45;
+    int j46;
+    int j47;
+    int j48;
+    int j49;
+    int j50;
+    int j51;
+    int j52;
+    int j53;
+    int j54;
+    int j55;
+    int j56;
+    int j57;
+    int j58;
+    int j59;
+    int j60;
+    int j61;
+    int j62;
+    int j63;
+    int j64;
+    int j65;
+    int j66;
+
+    public B t4;
+
+    int j67;
+    int j68;
+    int j69;
+    int j70;
+    int j71;
+    int j72;
+    int j73;
+    int j74;
+    int j75;
+    int j76;
+    int j77;
+    int j78;
+    int j79;
+    int j80;
+    int j81;
+    int j82;
+    int j83;
+    int j84;
+    int j85;
+    int j86;
+    int j87;
+    int j88;
+    int j89;
+    int j90;
+    int j91;
+    int j92;
+    int j93;
+    int j94;
+    int j95;
+    int j96;
+    int j97;
+    int j98;
+    int j99;
+}
+
+
+
+
+class CC
+{
+    public C[] array;
+    public CC(int size)
+    {
+        array = new C[size];
+    }
+}
+
+
+class TestMark
+{
+
+    public static int Main(string[] arg)
+    {
+
+        Console.WriteLine("Before allocation: {0}", TestMark.GetCommitted());
+
+        CC cc = new CC(500000);
+        cc.array[1024].t1 = new A();
+        cc.array[1024].t1.a = 3;
+        cc.array[1024].t2 = new B();
+        cc.array[1024].t2.b = 4;
+
+        long a = TestMark.GetCommitted();
+        Console.WriteLine("After allocation: {0}", a);
+        Console.WriteLine();
+        Console.WriteLine("Collecting...");
+        for (int i=0; i<100; i++)
+        {
+            GC.Collect();
+        }
+
+        long b= TestMark.GetCommitted();
+        Console.WriteLine("After 100 Collections: {0}", b);
+        GC.KeepAlive(cc);
+
+        if (Math.Abs(b- a) > (a/2))
+        {
+            Console.WriteLine("failed");
+            return 0;
+        }
+
+        Console.WriteLine("passed");
+        return 100;
+
+
+    }
+
+    [DllImport( "Kernel32.dll", CharSet=CharSet.Ansi )]
+    public static extern bool GlobalMemoryStatusEx( MemoryStatusEx memStatus);
+
+    public static long GetCommitted()
+    {
+        MemoryStatusEx mex = new MemoryStatusEx();
+        mex.length = Marshal.SizeOf(mex);
+        GlobalMemoryStatusEx(mex);
+        return mex.totalPageFile - mex.availPageFile;
+    }
+
+}
+
+[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi )]
+public class MemoryStatusEx
+{
+    public int length = 0;
+    public int memoryLoad = 0;
+    public long totalPhys = 0;
+    public long availPhys = 0;
+    public long totalPageFile = 0;
+    public long availPageFile = 0;
+    public long totalVirtual = 0;
+    public long availVirtual = 0;
+    public long availExtendedVirtual = 0;
+}
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/437657/437657.csproj b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/437657/437657.csproj
new file mode 100644 (file)
index 0000000..c07f5aa
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="437657.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/437657/app.config b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/437657/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/445488/445488.cs b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/445488/445488.cs
new file mode 100644 (file)
index 0000000..c2b356c
--- /dev/null
@@ -0,0 +1,135 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime;
+using System.Diagnostics;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Unicode )]
+public class Node
+{
+    GCHandle gch1;
+    byte[] pinnedData1;
+    public Node Next;
+
+
+    public Node()
+    {
+        pinnedData1 = new byte[1024*50];
+        gch1 = GCHandle.Alloc(pinnedData1, GCHandleType.Pinned);
+    }
+}
+
+public class Test
+{
+    //public static PerformanceCounter PC;
+
+
+    public static int Main()
+    {
+        List<byte[]> list = new List<byte[]>();
+        List<GCHandle> glist = new List<GCHandle>();
+        //PC = new PerformanceCounter(".NET CLR Memory", "Gen 0 heap size", "445488", ".");
+        long count =0;
+
+        while (count <= 124979200)
+        {
+            //float gen0size = PC.NextValue();
+            byte[] b = new byte[1024*50];
+            count += (1024*50);
+
+            if (count % (1024*2500)==0)
+            {
+                glist.Add(GCHandle.Alloc(b, GCHandleType.Pinned));
+            }
+
+            list.Add(b);
+            //Console.WriteLine("{0} {1:F}",count, gen0size);
+        }
+
+        GC.KeepAlive(list);
+        GC.KeepAlive(glist);
+        return 100;
+
+    }
+
+}
+
+/*
+124979200 3075360.00
+---------------------------
+424916.exe - Assert Failure (PID 2336, Thread 1248/4e0)
+---------------------------
+mi1 >= 0
+
+MSCORWKS! WKS::gc_heap::allocate_in_expanded_heap + 0x181 (0x5db32de9)
+MSCORWKS! WKS::gc_heap::realloc_plug + 0x1B5 (0x5db36a16)
+MSCORWKS! WKS::gc_heap::realloc_in_brick + 0x75 (0x5db36b3d)
+MSCORWKS! WKS::gc_heap::realloc_plugs + 0xAE (0x5db36bff)
+MSCORWKS! WKS::gc_heap::expand_heap + 0x478 (0x5db4049e)
+MSCORWKS! WKS::gc_heap::plan_phase + 0x1167 (0x5db43383)
+MSCORWKS! WKS::gc_heap::gc1 + 0x92 (0x5db43d85)
+MSCORWKS! WKS::gc_heap::garbage_collect + 0x3FE (0x5db44ee7)
+MSCORWKS! WKS::GCHeap::GarbageCollectGeneration + 0x23D (0x5db45162)
+MSCORWKS! WKS::gc_heap::allocate_more_space + 0x45A (0x5db456ae)
+
+f:\pd7\ndp\clr\src\vm\gc.cpp, Line: 7464
+
+Abort - Kill program
+Retry - Debug
+Ignore - Keep running
+
+
+Image:
+D:\temp\424916.exe
+
+---------------------------
+Abort   Retry   Ignore
+---------------------------
+
+Ignoring the asserts generates the AV from the bug report:
+
+
+ # ChildEBP RetAddr
+00 0012d250 5e24645f mscorwks!DbgAssertDialog+0x394
+01 0012d618 5dcedf7c mscorwks!CHECK::Trigger+0x2df
+02 0012d800 5dcedb2d mscorwks!CLRVectoredExceptionHandlerPhase2+0x33c
+03 0012d864 5d9cfd67 mscorwks!CLRVectoredExceptionHandler+0xcd
+04 0012d890 5d9cfc4a mscorwks!CPFH_FirstPassHandler+0xc7
+05 0012d8c4 7c9037bf mscorwks!COMPlusFrameHandler+0x14a
+WARNING: Stack unwind information not available. Following frames may be wrong.
+06 0012d8e8 7c90378b ntdll!RtlConvertUlongToLargeInteger+0x7a
+07 0012d998 7c90eafa ntdll!RtlConvertUlongToLargeInteger+0x46
+08 0012dca4 5e03ec96 ntdll!KiUserExceptionDispatcher+0xe
+09 0012dcb8 5e03ea89 mscorwks!WKS::gc_heap::gcmemcopy+0x86
+0a 0012dce4 5e03eda4 mscorwks!WKS::gc_heap::compact_plug+0xf9
+0b 0012dd18 5e03f02f mscorwks!WKS::gc_heap::compact_in_brick+0xd4
+0c 0012dd5c 5e03bce5 mscorwks!WKS::gc_heap::compact_phase+0x24f
+0d 0012df5c 5e03618e mscorwks!WKS::gc_heap::plan_phase+0x19e5
+0e 0012dfa0 5e036a6f mscorwks!WKS::gc_heap::gc1+0xae
+0f 0012dfb4 5e04af14 mscorwks!WKS::gc_heap::garbage_collect+0x4df
+10 0012dfe4 5e0333b8 mscorwks!WKS::GCHeap::GarbageCollectGeneration+0x1e4
+11 0012e0b4 5e04a17b mscorwks!WKS::gc_heap::allocate_more_space+0x4a8
+12 0012e0d4 5e04a9e8 mscorwks!WKS::gc_heap::allocate+0x8b
+13 0012e184 5de64ff6 mscorwks!WKS::GCHeap::Alloc+0x1f8
+14 0012e290 5de65ab8 mscorwks!Alloc+0x256
+15 0012e388 5de39ead mscorwks!FastAllocatePrimitiveArray+0x3f8
+*** WARNING: Unable to verify checksum for D:\WINDOWS\Microsoft.NET\Framework\v2.0.x86dbg\assembly\NativeImages_v2.0.x86dbg_32\mscorlib\ab6a82069375373ebc7e85bf2de124cb\mscorlib.ni.dll
+*** ERROR: Module load completed but symbols could not be loaded for D:\WINDOWS\Microsoft.NET\Framework\v2.0.x86dbg\assembly\NativeImages_v2.0.x86dbg_32\mscorlib\ab6a82069375373ebc7e85bf2de124cb\mscorlib.ni.dll
+16 0012e54c 5b69d907 mscorwks!JIT_NewArr1+0x4dd
+17 0012e610 5b69d716 mscorlib_ni!Microsoft.Win32.RegistryKey.InternalGetValue(System.String, System.Object, Boolean, Boolean)+0x147
+18 0012e610 5b69d716 mscorlib_ni!Microsoft.Win32.RegistryKey.InternalGetValue(System.String, System.Object, Boolean, Boolean)+0x147
+19 00000000 7a7e6865 mscorlib_ni!Microsoft.Win32.RegistryKey.GetValue(System.String)+0x36
+*** WARNING: Unable to verify checksum for D:\WINDOWS\Microsoft.NET\Framework\v2.0.x86dbg\assembly\NativeImages_v2.0.x86dbg_32\System\08fb29f559b89437a7fc3f4a7dbde9c1\System.ni.dll
+*** ERROR: Module load completed but symbols could not be loaded for D:\WINDOWS\Microsoft.NET\Framework\v2.0.x86dbg\assembly\NativeImages_v2.0.x86dbg_32\System\08fb29f559b89437a7fc3f4a7dbde9c1\System.ni.dll
+1a 0012e66c 7a7e617f System_ni!System.Diagnostics.PerformanceMonitor.GetData(System.String)+0x55
+1b 0012e6a0 7a7e57fe System_ni!System.Diagnostics.PerformanceCounterLib.GetPerformanceData(System.String)+0x97
+1c 00a855a4 7a7e5742 System_ni!System.Diagnostics.PerformanceCounterLib.GetCategorySample(System.String)+0x62
+1d 0012e738 7a7e24e0 System_ni!System.Diagnostics.PerformanceCounterLib.GetCategorySample(System.String, System.String)+0x36
+1e 0012e738 7a7e2651 System_ni!System.Diagnostics.PerformanceCounter.NextSample()+0x64
+1f 04ffb000 02c800f0 System_ni!System.Diagnostics.PerformanceCounter.NextValue()+0x21
+20 04ffb000 00000000 445488!Test.Main()+0x80
+*/
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/445488/445488.csproj b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/445488/445488.csproj
new file mode 100644 (file)
index 0000000..f19d924
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="445488.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/445488/app.config b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/445488/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/452950/452950.cs b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/452950/452950.cs
new file mode 100644 (file)
index 0000000..9b3a1ac
--- /dev/null
@@ -0,0 +1,54 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+public class b452950
+{
+    public static List<GCHandle> list = new List<GCHandle>();
+    public static int DEFAULT = 1000;
+
+    public static int Main(string[] args)
+    {
+
+        int numIterations = 0;
+        if (args.Length >0)
+        {
+            Int32.TryParse(args[0], out numIterations);
+            if (numIterations<0)
+            {
+                numIterations=DEFAULT;
+            }
+        }
+        else
+        {
+            numIterations= DEFAULT;
+        }
+
+        // fragment the heap
+        for (int i=0; i<numIterations; i++)
+        {
+            byte[] b = new byte[1024*50];
+            list.Add(GCHandle.Alloc(b, GCHandleType.Pinned));
+            byte[] b2 = new byte[1024*50];
+
+        }
+
+        int gcCount = GC.CollectionCount(GC.MaxGeneration);
+        Console.WriteLine(gcCount);
+
+        // if we do a full collection <= (5% of the interations) times, we pass
+        if (gcCount <= (numIterations*0.05))
+        {
+            Console.WriteLine("Passed");
+            return 100;
+        }
+
+        Console.WriteLine("Failed");
+        return 1;
+    }
+}
+
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/452950/452950.csproj b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/452950/452950.csproj
new file mode 100644 (file)
index 0000000..247966c
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="452950.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/452950/app.config b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/452950/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/460373/460373.cs b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/460373/460373.cs
new file mode 100644 (file)
index 0000000..9f8c18b
--- /dev/null
@@ -0,0 +1,117 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// seg 4MB, gen0 4MB: regression test for 424916
+// seg 8MB, gen0 4MB regression test for 460373
+
+using System;
+using System.Runtime;
+using System.Diagnostics;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+namespace b424916
+{
+
+    [ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Unicode )]
+    public class Node
+    {
+        GCHandle gch1;
+        byte[] unpinnedData1;
+        byte[] pinnedData1;
+        byte[] unpinnedData2;
+        byte[] unpinnedData3;
+        byte[] unpinnedData4;
+        byte[] pinnedData2;
+        byte[] unpinnedData5;
+        GCHandle gch2;
+        public Node Next;
+
+       [System.Security.SecuritySafeCritical]
+        public Node()
+        {
+
+            pinnedData1 = new byte[10];
+            gch1 = GCHandle.Alloc(pinnedData1, GCHandleType.Pinned);
+            pinnedData2 = new byte[10];
+            gch2 = GCHandle.Alloc(pinnedData2, GCHandleType.Pinned);
+
+            unpinnedData1 = new byte[1024*80];
+            unpinnedData2 = new byte[1024*80];
+            unpinnedData3 = new byte[1024*80];
+            unpinnedData4 = new byte[1024*80];
+            unpinnedData5 = new byte[1024*80];
+
+        }
+    }
+
+    public class Test
+    {
+
+        public static int Main()
+        {
+
+            Node head = new Node();
+            Node cur = head;
+
+            for (int i=0; i<1250; i++)
+            {
+                cur.Next = new Node();
+                cur = cur.Next;
+                GC.KeepAlive(head);
+
+            }
+
+            return 100;
+        }
+    }
+}
+
+/*
+PD7 asserts:
+
+segment size: 4MB
+gen0 initial size: 4MB
+(at time of assert, gen0 is ~8MB)
+
+Assert failure(PID 2560 [0x00000a00], Thread: 2488 [0x9b8]): (heap_segment_rw (g
+eneration_start_segment (gen))!= ephemeral_heap_segment) || (gap_start > generat
+ion_allocation_start (gen))
+
+MSCORWKS! WKS::gc_heap::thread_gap + 0x5A (0x5db3bb55)
+MSCORWKS! WKS::gc_heap::plan_phase + 0x17CF (0x5db439eb)
+MSCORWKS! WKS::gc_heap::gc1 + 0x92 (0x5db43d85)
+MSCORWKS! WKS::gc_heap::garbage_collect + 0x3FE (0x5db44ee7)
+MSCORWKS! WKS::GCHeap::GarbageCollectGeneration + 0x23D (0x5db45162)
+MSCORWKS! WKS::gc_heap::allocate_more_space + 0x124 (0x5db45378)
+MSCORWKS! WKS::GCHeap::Alloc + 0x11D (0x5db4619d)
+MSCORWKS! Alloc + 0x13A (0x5d9c90b8)
+MSCORWKS! FastAllocatePrimitiveArray + 0x21B (0x5d9c9da2)
+MSCORWKS! JIT_NewArr1 + 0x2CF (0x5d9d5155)
+    File: f:\pd7\ndp\clr\src\vm\gc.cpp, Line: 12792 Image:
+D:\temp\424916.exe
+
+
+
+segment size: 8MB
+gen0 initial size: 4MB
+(at time of assert, gen0 is ~8KB)
+
+Assert failure(PID 2172 [0x0000087c], Thread: 3668 [0xe54]): !"Can't allocate if
+ no free space"
+
+MSCORWKS! WKS::gc_heap::allocate_in_expanded_heap + 0x276 (0x5db32ede)
+MSCORWKS! WKS::gc_heap::realloc_plug + 0x1B5 (0x5db36a16)
+MSCORWKS! WKS::gc_heap::realloc_plugs + 0xE9 (0x5db36c3a)
+MSCORWKS! WKS::gc_heap::expand_heap + 0x478 (0x5db4049e)
+MSCORWKS! WKS::gc_heap::plan_phase + 0x1167 (0x5db43383)
+MSCORWKS! WKS::gc_heap::gc1 + 0x92 (0x5db43d85)
+MSCORWKS! WKS::gc_heap::garbage_collect + 0x3FE (0x5db44ee7)
+MSCORWKS! WKS::GCHeap::GarbageCollectGeneration + 0x23D (0x5db45162)
+MSCORWKS! WKS::GCHeap::GarbageCollectTry + 0x38 (0x5db4627e)
+MSCORWKS! WKS::GCHeap::GarbageCollect + 0x3B (0x5db462bd)
+    File: f:\pd7\ndp\clr\src\vm\gc.cpp, Line: 7490 Image:
+D:\temp\424916.exe
+
+*/
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/460373/460373.csproj b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/460373/460373.csproj
new file mode 100644 (file)
index 0000000..7f272f5
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="460373.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/460373/app.config b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/460373/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/462651/462651.cs b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/462651/462651.cs
new file mode 100644 (file)
index 0000000..6c2272a
--- /dev/null
@@ -0,0 +1,100 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.Text;
+using System.Runtime.InteropServices;
+
+
+class Mainy {
+
+[DllImport("kernel32")]
+public static extern void DebugBreak();
+
+
+public static void AllocStart()
+{
+    char [] bigCharArray = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g'};
+
+    int iCur = 0;
+    Random r = new Random(1);
+    Object [] cache = new Object[100];
+    String teststr = new String(bigCharArray);
+    String [] strArray = new String[1024];
+
+    // Allocate a bundle of "small" large objects and an occasional
+    // huge large object
+
+    int iCacheClear = 0; // when 1000, clear the cache
+    try
+    {
+        //while(true)
+        for (int j=0; j<5000; j++)
+        {
+            int iVal = r.Next(1,100);
+            if (iVal < 80)
+            {
+                cache[iCur] = new Byte[2];
+                Thread.Sleep(5);
+            }
+            else
+            {
+                StringBuilder sb = new StringBuilder();
+                for (int k=0; k < 1024; k++){
+                    sb = sb.Append(teststr);
+                }
+                cache[iCur] = sb.ToString();
+            }
+            iCur = ((iCur + 1) % 50);
+            iCacheClear++;
+            if (iCacheClear == 1000)
+            {
+                Console.WriteLine("Clearing cache");
+                for(int i=0;i<50;i++)
+                    cache[i] = null;
+                iCacheClear = 0;
+            }
+        }
+    }
+    catch (OutOfMemoryException)
+    {
+        Console.WriteLine("OOM");
+    }
+}
+
+public static int Main() {
+
+
+
+    int arrayLen = 1024*5;
+    Byte [][] cache = new Byte[arrayLen][];
+
+    for(int j=0; j< arrayLen; j++){
+        cache[j] = new Byte[1024];
+    }
+
+    Thread t = new Thread(new ThreadStart(AllocStart));
+    t.Start();
+
+
+    Thread t6 = new Thread(new ThreadStart(AllocStart));
+    t6.Start();
+
+    Thread t2 = new Thread(new ThreadStart(AllocStart));
+    t2.Start();
+
+
+    for(int i=0; i<1024; i++){
+        Thread.Sleep(250);
+        int j = cache[i].Length;
+    }
+
+    Console.WriteLine("finished");
+    return 100;
+}
+
+}
+
+
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/462651/462651.csproj b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/462651/462651.csproj
new file mode 100644 (file)
index 0000000..8091381
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="462651.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/462651/app.config b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/462651/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
index 9734464..dce937b 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/471729/project.json b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/471729/project.json
deleted file mode 100644 (file)
index 14c11d2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "dependencies": {
-    "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
-    "System.Collections": "4.0.10",
-    "System.Collections.NonGeneric": "4.0.1-beta-23302",
-    "System.Collections.Specialized": "4.0.1-beta-23302",
-    "System.ComponentModel": "4.0.1-beta-23302",
-    "System.Console": "4.0.0-beta-23302",
-    "System.Diagnostics.Process": "4.0.0-beta-23302",
-    "System.Globalization": "4.0.10",
-    "System.Globalization.Calendars": "4.0.0",
-    "System.IO": "4.0.10",
-    "System.IO.FileSystem": "4.0.0",
-    "System.IO.FileSystem.Primitives": "4.0.0",
-    "System.Linq": "4.0.1-beta-23302",
-    "System.Linq.Queryable": "4.0.1-beta-23302",
-    "System.Reflection": "4.0.10",
-    "System.Reflection.Primitives": "4.0.0",
-    "System.Runtime": "4.0.20",
-    "System.Runtime.Extensions": "4.0.10",
-    "System.Runtime.Handles": "4.0.0",
-    "System.Runtime.InteropServices": "4.0.20",
-    "System.Runtime.Loader": "4.0.0-beta-23302",
-    "System.Text.Encoding": "4.0.10",
-    "System.Threading": "4.0.10",
-    "System.Xml.ReaderWriter": "4.0.11-beta-23302",
-    "System.Xml.XDocument": "4.0.11-beta-23302",
-    "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
-  },
-  "frameworks": {
-    "dnxcore50": {}
-  }
-}
index 217914d..f6d7355 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/476725/project.json b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/476725/project.json
deleted file mode 100644 (file)
index 14c11d2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "dependencies": {
-    "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
-    "System.Collections": "4.0.10",
-    "System.Collections.NonGeneric": "4.0.1-beta-23302",
-    "System.Collections.Specialized": "4.0.1-beta-23302",
-    "System.ComponentModel": "4.0.1-beta-23302",
-    "System.Console": "4.0.0-beta-23302",
-    "System.Diagnostics.Process": "4.0.0-beta-23302",
-    "System.Globalization": "4.0.10",
-    "System.Globalization.Calendars": "4.0.0",
-    "System.IO": "4.0.10",
-    "System.IO.FileSystem": "4.0.0",
-    "System.IO.FileSystem.Primitives": "4.0.0",
-    "System.Linq": "4.0.1-beta-23302",
-    "System.Linq.Queryable": "4.0.1-beta-23302",
-    "System.Reflection": "4.0.10",
-    "System.Reflection.Primitives": "4.0.0",
-    "System.Runtime": "4.0.20",
-    "System.Runtime.Extensions": "4.0.10",
-    "System.Runtime.Handles": "4.0.0",
-    "System.Runtime.InteropServices": "4.0.20",
-    "System.Runtime.Loader": "4.0.0-beta-23302",
-    "System.Text.Encoding": "4.0.10",
-    "System.Threading": "4.0.10",
-    "System.Xml.ReaderWriter": "4.0.11-beta-23302",
-    "System.Xml.XDocument": "4.0.11-beta-23302",
-    "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
-  },
-  "frameworks": {
-    "dnxcore50": {}
-  }
-}
index 6062401..eb17c7b 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/485617/project.json b/src/coreclr/tests/src/GC/Regressions/v2.0-beta2/485617/project.json
deleted file mode 100644 (file)
index 14c11d2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "dependencies": {
-    "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
-    "System.Collections": "4.0.10",
-    "System.Collections.NonGeneric": "4.0.1-beta-23302",
-    "System.Collections.Specialized": "4.0.1-beta-23302",
-    "System.ComponentModel": "4.0.1-beta-23302",
-    "System.Console": "4.0.0-beta-23302",
-    "System.Diagnostics.Process": "4.0.0-beta-23302",
-    "System.Globalization": "4.0.10",
-    "System.Globalization.Calendars": "4.0.0",
-    "System.IO": "4.0.10",
-    "System.IO.FileSystem": "4.0.0",
-    "System.IO.FileSystem.Primitives": "4.0.0",
-    "System.Linq": "4.0.1-beta-23302",
-    "System.Linq.Queryable": "4.0.1-beta-23302",
-    "System.Reflection": "4.0.10",
-    "System.Reflection.Primitives": "4.0.0",
-    "System.Runtime": "4.0.20",
-    "System.Runtime.Extensions": "4.0.10",
-    "System.Runtime.Handles": "4.0.0",
-    "System.Runtime.InteropServices": "4.0.20",
-    "System.Runtime.Loader": "4.0.0-beta-23302",
-    "System.Text.Encoding": "4.0.10",
-    "System.Threading": "4.0.10",
-    "System.Xml.ReaderWriter": "4.0.11-beta-23302",
-    "System.Xml.XDocument": "4.0.11-beta-23302",
-    "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
-  },
-  "frameworks": {
-    "dnxcore50": {}
-  }
-}
index b904841..56e1066 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-rtm/494226/project.json b/src/coreclr/tests/src/GC/Regressions/v2.0-rtm/494226/project.json
deleted file mode 100644 (file)
index 14c11d2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "dependencies": {
-    "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
-    "System.Collections": "4.0.10",
-    "System.Collections.NonGeneric": "4.0.1-beta-23302",
-    "System.Collections.Specialized": "4.0.1-beta-23302",
-    "System.ComponentModel": "4.0.1-beta-23302",
-    "System.Console": "4.0.0-beta-23302",
-    "System.Diagnostics.Process": "4.0.0-beta-23302",
-    "System.Globalization": "4.0.10",
-    "System.Globalization.Calendars": "4.0.0",
-    "System.IO": "4.0.10",
-    "System.IO.FileSystem": "4.0.0",
-    "System.IO.FileSystem.Primitives": "4.0.0",
-    "System.Linq": "4.0.1-beta-23302",
-    "System.Linq.Queryable": "4.0.1-beta-23302",
-    "System.Reflection": "4.0.10",
-    "System.Reflection.Primitives": "4.0.0",
-    "System.Runtime": "4.0.20",
-    "System.Runtime.Extensions": "4.0.10",
-    "System.Runtime.Handles": "4.0.0",
-    "System.Runtime.InteropServices": "4.0.20",
-    "System.Runtime.Loader": "4.0.0-beta-23302",
-    "System.Text.Encoding": "4.0.10",
-    "System.Threading": "4.0.10",
-    "System.Xml.ReaderWriter": "4.0.11-beta-23302",
-    "System.Xml.XDocument": "4.0.11-beta-23302",
-    "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
-  },
-  "frameworks": {
-    "dnxcore50": {}
-  }
-}
index 184afab..7148f08 100644 (file)
@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
-// originally a regression test for VSWhidbey 158720
-
 using System;
 internal class AllocBug
 {
index cd52324..12e6b20 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
diff --git a/src/coreclr/tests/src/GC/Regressions/v2.0-rtm/544701/project.json b/src/coreclr/tests/src/GC/Regressions/v2.0-rtm/544701/project.json
deleted file mode 100644 (file)
index 14c11d2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "dependencies": {
-    "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
-    "System.Collections": "4.0.10",
-    "System.Collections.NonGeneric": "4.0.1-beta-23302",
-    "System.Collections.Specialized": "4.0.1-beta-23302",
-    "System.ComponentModel": "4.0.1-beta-23302",
-    "System.Console": "4.0.0-beta-23302",
-    "System.Diagnostics.Process": "4.0.0-beta-23302",
-    "System.Globalization": "4.0.10",
-    "System.Globalization.Calendars": "4.0.0",
-    "System.IO": "4.0.10",
-    "System.IO.FileSystem": "4.0.0",
-    "System.IO.FileSystem.Primitives": "4.0.0",
-    "System.Linq": "4.0.1-beta-23302",
-    "System.Linq.Queryable": "4.0.1-beta-23302",
-    "System.Reflection": "4.0.10",
-    "System.Reflection.Primitives": "4.0.0",
-    "System.Runtime": "4.0.20",
-    "System.Runtime.Extensions": "4.0.10",
-    "System.Runtime.Handles": "4.0.0",
-    "System.Runtime.InteropServices": "4.0.20",
-    "System.Runtime.Loader": "4.0.0-beta-23302",
-    "System.Text.Encoding": "4.0.10",
-    "System.Threading": "4.0.10",
-    "System.Xml.ReaderWriter": "4.0.11-beta-23302",
-    "System.Xml.XDocument": "4.0.11-beta-23302",
-    "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
-  },
-  "frameworks": {
-    "dnxcore50": {}
-  }
-}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Affinity/affinitizer.cs b/src/coreclr/tests/src/GC/Scenarios/Affinity/affinitizer.cs
new file mode 100644 (file)
index 0000000..f780cc5
--- /dev/null
@@ -0,0 +1,129 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Threading;
+using System.Diagnostics;
+
+public class Affinitizer
+{
+
+    public static void Usage()
+    {
+        Console.WriteLine("Usage:");
+        Console.WriteLine("affinitizer.exe <num procs (0 for random)> <\"assembly.exe arg list\"> [random seed]");
+    }
+
+    public static int Main(string[] args)
+    {
+
+        if ((args.Length < 2) || (args.Length > 3))
+        {
+            Usage();
+            return 0;
+        }
+
+        int numProcessors = Environment.ProcessorCount;
+
+        // get affinity
+        IntPtr affinity = IntPtr.Zero;
+        int a = 0;
+        if ( (!int.TryParse(args[0], out a)) || (a < 0) )
+        {
+            Usage();
+            return 0;        
+        }
+        // cap the number of procs to the max on the machine
+        affinity = new IntPtr(Math.Min(a, numProcessors));
+
+        // get process name and args
+        string processName = null;
+        string processArgs = null;
+        int firstSpaceIndex = args[1].Trim().IndexOf(' ');
+        if (firstSpaceIndex < 0)
+        {
+            // no args
+            processName = args[1];
+        }
+        else
+        {
+            processName = args[1].Substring(0, firstSpaceIndex);
+            processArgs = args[1].Substring(firstSpaceIndex + 1);
+        }
+
+        // get random seed
+        int seed = 0;
+        if (args.Length == 3)
+        {
+            if (!int.TryParse(args[2], out seed))
+            {
+                Usage();
+                return 0;
+            }
+        }
+        else
+        {
+            seed = (int)DateTime.Now.Ticks;
+        }
+        
+        Console.WriteLine("Running on a {0}-processor machine", numProcessors);
+        
+        return RunTest(affinity, processName, processArgs, seed);
+    }
+    
+
+    public static int RunTest(IntPtr affinity, string processName, string processArgs, int seed)
+    {
+
+        // run the test
+        Random rand = null;
+
+        Process p = Process.Start(processName, processArgs);
+        
+        // cannot set the affinity before the process starts in managed code
+        // This code executes so quickly that the GC heaps have not yet been initialized,
+        // so it works.
+        if (affinity != IntPtr.Zero)
+        {
+            // set affinity to (2^n)-1, where n=affinity
+            int newAffinity = (int)Math.Pow(2, affinity.ToInt32())-1;
+            p.ProcessorAffinity = new IntPtr(newAffinity);
+            Console.WriteLine("Affinitizing to {0}", newAffinity); 
+        }
+        else
+        {
+            rand = new Random(seed);
+            Console.WriteLine("Using random seed: {0}", seed);
+        }
+
+        while (!p.HasExited)
+        {
+            // change affinity randomly every 5 seconds
+            Thread.Sleep(5000);
+            if (affinity == IntPtr.Zero)
+            {
+                try
+                {
+                    // randomly change the affinity between 1 and (2^n)-1, where n=numProcessors
+                    int newAffinity = rand.Next(1, (int)Math.Pow(2, Environment.ProcessorCount)-1);
+                    p.ProcessorAffinity = new IntPtr(newAffinity);
+                    Console.WriteLine("Affinitizing to {0}", newAffinity);
+                }
+                // we couldn't set the affinity, so just exit
+                catch (InvalidOperationException)
+                {
+                    break;
+                }
+                catch (System.ComponentModel.Win32Exception)
+                {
+                    break;
+                }
+            }
+
+        }
+
+        Console.WriteLine("Exiting with exit code {0}", p.ExitCode);
+        return p.ExitCode;
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Affinity/affinitizer.csproj b/src/coreclr/tests/src/GC/Scenarios/Affinity/affinitizer.csproj
new file mode 100644 (file)
index 0000000..6dc8ce2
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestKind>SharedLibrary</CLRTestKind>    
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="affinitizer.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/Affinity/app.config b/src/coreclr/tests/src/GC/Scenarios/Affinity/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/BaseFinal/app.config b/src/coreclr/tests/src/GC/Scenarios/BaseFinal/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/BaseFinal/basefinal.cs b/src/coreclr/tests/src/GC/Scenarios/BaseFinal/basefinal.cs
new file mode 100644 (file)
index 0000000..5f61f2e
--- /dev/null
@@ -0,0 +1,143 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*******************************************************************************/
+/* Test:    BaseFinal
+/* Purpose: 1. if finalize() is called before the objects are GCed.
+/*      2. resurrect the object while the finalize() method is call.
+/*******************************************************************************/
+
+namespace DefaultNamespace {
+    using System;
+    using System.Collections.Generic;
+
+    internal class BaseFinal
+    {
+// disabling unused variable warning
+#pragma warning disable 0414
+        internal static Object StObj;
+#pragma warning restore 0414
+
+        public static int Main(String [] str)
+        {
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+            CreateObj temp = new CreateObj();
+            if (temp.RunTest())
+            {
+                Console.WriteLine( "Test passed!" );
+                return 100;
+            }
+            else
+            {
+                Console.WriteLine( "Test failed!" );
+                return 1;
+            }
+        }
+
+
+        ~BaseFinal()
+        {
+            BaseFinal.StObj = ( this );
+            Console.WriteLine( "Main class Finalize().");
+        }
+
+        public void CreateNode( int i )
+        {
+            BNode rgobj = new BNode( i );
+        }
+    }
+
+
+    internal class BNode
+    {
+        public static int icCreateNode = 0;
+        public static int icFinalNode = 0;
+        internal static List<object> rlNode = new List<object>( );
+        public int [] mem;
+
+        public BNode( int i )
+        {
+            icCreateNode++;
+            mem = new int[i];
+            mem[0] = 99;
+            if(i > 1 )
+            {
+                mem[mem.Length-1] = mem.Length-1;
+            }
+        }
+
+        ~BNode()
+        {
+            icFinalNode++;
+            rlNode.Add(this);  //resurrect objects
+        }
+    }
+
+
+    internal class CreateObj
+    {
+
+        public BaseFinal mv_Obj;
+
+// disabling unused variable warning
+#pragma warning disable 0414
+        public BNode obj;
+#pragma warning restore 0414
+
+
+        public CreateObj()
+        {
+
+            mv_Obj = new BaseFinal();
+            //Printing GetTotalMemory is commented out so that the test can build on RedHawk
+            //Console.WriteLine("before test started, the heapsize is {0}", GC.GetTotalMemory(false));
+
+            for( int i=1; i< 1000; i++)
+            {
+                obj = new BNode(i);     //create new one and delete the last one.
+                mv_Obj.CreateNode( i ); //create locate objects in createNode().
+            }
+            Console.Write(BNode.icCreateNode);
+             Console.WriteLine(" Nodes were created.");
+
+            //Console.WriteLine("after all objects were created, the heapsize is " + GC.GetTotalMemory(false));
+        }
+
+        public bool RunTest()
+        {
+            obj = null;
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+
+            Console.Write(BNode.icFinalNode);
+            Console.WriteLine(" Nodes were finalized and resurrected.");
+            //Console.WriteLine("after all objects were deleted and resurrected in Finalize() , the heapsize is " + GC.GetTotalMemory(false));
+
+            for(int i=0; i< BNode.rlNode.Count; i++)
+            {
+                BNode oldNode = (BNode)BNode.rlNode[ i ];
+                if ( oldNode.mem[0] != 99 )
+                {
+                    Console.WriteLine( "One Node is not resurrected correctly.");
+                }
+                oldNode = null;
+                BNode.rlNode[ i ] = null;
+            }
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+
+            //Console.WriteLine("after all objects were deleted , the heapsize is " + GC.GetTotalMemory(false));
+
+            return ( BNode.icCreateNode == BNode.icFinalNode );
+
+
+        }
+    }
+
+
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/BaseFinal/basefinal.csproj b/src/coreclr/tests/src/GC/Scenarios/BaseFinal/basefinal.csproj
new file mode 100644 (file)
index 0000000..a6b0e5d
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="BaseFinal.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/BinTree/app.config b/src/coreclr/tests/src/GC/Scenarios/BinTree/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/BinTree/bintree.cs b/src/coreclr/tests/src/GC/Scenarios/BinTree/bintree.cs
new file mode 100644 (file)
index 0000000..a58dd8f
--- /dev/null
@@ -0,0 +1,181 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace DefaultNamespace {
+    using System.Threading;
+    using System;
+    using System.IO;
+
+    public enum TreeType
+    {
+        Normal,
+        Growing,
+        Living
+    }
+
+    public class Node
+    {
+        internal int m_data;
+        internal Node m_pLeft;
+        internal Node m_pRight;
+        internal byte[] m_aMem;
+        internal bool Switch;
+        internal int m_iCount;
+
+        public Node()
+        {
+            m_aMem = new byte[10];
+            m_aMem[0] = (byte)10;
+            m_aMem[9] = (byte)10;
+        }
+
+        public void Live()
+        {
+            if (Switch)
+            {
+                m_aMem = new byte[1000];
+                m_aMem[0] = (byte) 10;
+                m_aMem[999] = (byte) 10;
+            }
+            else
+            {
+                m_aMem = new byte[10];
+                m_aMem[0] = (byte) 10;
+                m_aMem[9] = (byte) 10;
+            }
+
+            Switch = !Switch;
+        }
+
+        public void Grow()
+        {
+            m_aMem = new byte[(m_iCount+=100)];
+            m_aMem[0] = (byte) 10;
+            m_aMem[m_iCount-1] = (byte) 10;
+        }
+    }
+
+
+    public class BinTree
+    {
+        internal Node m_pRoot;
+        internal Random m_Random;
+        internal TreeType m_TreeType;
+
+        public BinTree(int ThreadId, TreeType treeType)
+        {
+            // the following intended to ensure the console output was legible...
+            //Console.SetOut(TextWriter.Synchronized(Console.Out));
+            m_TreeType = treeType;
+            m_pRoot = null;
+            m_Random = new Random();
+        }
+
+
+        public void Empty (int ThreadId)
+        {
+            Console.Out.WriteLine("Thread " + ThreadId + ": Tree Empty");
+            m_pRoot = null;
+        }
+
+
+        public void AddNodes (int howMany, int ThreadId)
+        {
+            for (int i = 0; i < howMany; i++)
+            {
+                m_pRoot = Insert(m_pRoot, m_Random.Next(100));
+            }
+            Console.Out.WriteLine("Thread " + ThreadId + " Added: " + howMany + " Nodes: " + GC.GetTotalMemory(false));
+        }
+
+
+        public void DeleteNodes (int howMany, int ThreadId)
+        {
+            for (int i = 0; i < howMany; i++)
+            {
+                m_pRoot = Delete(m_pRoot, m_Random.Next(100) );
+            }
+            Console.Out.WriteLine("Thread " + ThreadId +" Deleted: " + howMany + " Nodes: " + GC.GetTotalMemory(false));
+        }
+
+
+        public Node Insert(Node root, int element)
+        {
+            if(root == null)                                            //if is NULL make a new node
+            {                                                           //and copy number to the new node
+                root=new Node();                                        //make new node
+                root.m_data = element;                                  //copy number
+                root.m_pLeft=null ;                                     //set the children to NULL
+                root.m_pRight=null;
+            }
+            else if(element < root.m_data)
+            {
+                root.m_pLeft = Insert(root.m_pLeft, element);
+            }
+            else
+            {
+                root.m_pRight = Insert(root.m_pRight, element);
+            }
+
+            if (m_TreeType==TreeType.Growing)
+            {
+                root.Grow();
+            }
+            else if (m_TreeType==TreeType.Living)
+            {
+                root.Live();
+            }
+
+            return root;
+        }
+
+
+        public Node Delete(Node root, int element)
+        {
+            Node temp = null;
+
+            if (root == null)
+            {
+                return null;                                                //Node not found
+            }
+            else if (element == root.m_data)                                 //if it was the first data (node)
+            {
+                if(root.m_pRight == null)                                       //check if it has right child.
+                {                                                           //If it has no right child
+                    return root.m_pLeft;
+                }
+
+                if (root.m_pLeft == null)
+                {
+                    return root.m_pRight;
+                }
+                else
+                {
+                    for (temp = root.m_pLeft; temp.m_pRight != null; temp = temp.m_pRight);
+                    root.m_data = temp.m_data;
+                    root.m_pLeft = Delete(root.m_pLeft, temp.m_data);
+                }
+            }
+            else if (root.m_data > element)
+            {
+                root.m_pLeft = Delete(root.m_pLeft, element);
+            }
+            else
+            {
+                root.m_pRight = Delete(root.m_pRight, element);
+            }
+
+            if (m_TreeType==TreeType.Growing)
+            {
+                root.Grow();
+            }
+            else if (m_TreeType==TreeType.Living)
+            {
+                root.Live();
+            }
+
+            return root;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/BinTree/bintree.csproj b/src/coreclr/tests/src/GC/Scenarios/BinTree/bintree.csproj
new file mode 100644 (file)
index 0000000..8acbccd
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestKind>BuildOnly</CLRTestKind> 
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="BinTree.cs" />
+    <Compile Include="TreeThread.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/BinTree/thdtree.cs b/src/coreclr/tests/src/GC/Scenarios/BinTree/thdtree.cs
new file mode 100644 (file)
index 0000000..126f299
--- /dev/null
@@ -0,0 +1,50 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**
+ * Description:
+ *      Mainly stresses the GC by creating n threads each manipulating its own local binary tree structure.
+ *      Each thread in turn adds and deletes thousands of nodes from the binary tree.
+ */
+
+namespace DefaultNamespace {
+    using System.Threading;
+    using System;
+    using System.IO;
+
+    public class ThdTree
+    {
+
+        public static int Main (System.String[] Args)
+        {
+
+            Console.Out.WriteLine("Test should return with ExitCode 100 ...");
+            // sync console output Console.SetOut(TextWriter.Synchronized(Console.Out));
+
+            int iNofThread = 0;
+
+            if (Args.Length == 1)
+            {
+                if (!Int32.TryParse( Args[0], out iNofThread ))
+                {
+                    iNofThread = 2;
+                }
+            }
+            else
+            {
+                iNofThread = 2;
+            }
+
+            TreeThread Mv_LLTree;
+
+            int[] count = {10000, -5000, 3000, -6000, 0, 15000, 0, 10000,0,100,100};
+            for (int i = 0; i < iNofThread; i++)
+            {
+                Mv_LLTree = new TreeThread(i, TreeType.Normal, count);
+            }
+            return 100;
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/BinTree/thdtree.csproj b/src/coreclr/tests/src/GC/Scenarios/BinTree/thdtree.csproj
new file mode 100644 (file)
index 0000000..3d6ffe3
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="ThdTree.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="BinTree.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/BinTree/thdtreegrowingobj.cs b/src/coreclr/tests/src/GC/Scenarios/BinTree/thdtreegrowingobj.cs
new file mode 100644 (file)
index 0000000..2061844
--- /dev/null
@@ -0,0 +1,50 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**
+ * Description:
+ *      Mainly stresses the GC by creating n threads each manipulating its own local binary tree.
+ *      Differs from thdtree in a way that the nodes of the binary trees grow during the lifetime.
+ */
+
+
+
+namespace DefaultNamespace {
+    using System.Threading;
+    using System;
+    using System.IO;
+
+    public class ThdTreeGrowingObj
+    {
+
+        public static int Main (System.String[] Args)
+        {
+            Console.Out.WriteLine("Test should return with ExitCode 100 ...");
+            // console sync Console.SetOut(TextWriter.Synchronized(Console.Out));
+
+            int iNofThread = 0;
+
+            if (Args.Length == 1)
+            {
+                if (!Int32.TryParse( Args[0], out iNofThread ))
+                {
+                    iNofThread = 2;
+                }
+            }
+            else
+            {
+                iNofThread = 2;
+            }
+
+            int[] count = {300, 1000, -350, 0, 71, 200};
+            TreeThread Mv_TreeThread;
+            for (int i = 0; i < iNofThread; i++)
+            {
+                Mv_TreeThread = new TreeThread(i, TreeType.Growing, count);              //Each treethread object launches a thread
+            }
+            return 100;
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/BinTree/thdtreegrowingobj.csproj b/src/coreclr/tests/src/GC/Scenarios/BinTree/thdtreegrowingobj.csproj
new file mode 100644 (file)
index 0000000..d97506b
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="ThdTreeGrowingObj.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="BinTree.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/BinTree/thdtreelivingobj.cs b/src/coreclr/tests/src/GC/Scenarios/BinTree/thdtreelivingobj.cs
new file mode 100644 (file)
index 0000000..6ac0963
--- /dev/null
@@ -0,0 +1,49 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**
+ * Description:
+ *      Mainly stresses the GC by creating n threads each manipulating its own local binary tree.
+ *      Differs from thdtree in a way that the nodes of the binary trees are alive(meaning they
+ *      shrink and grow during their lifetime).
+ */
+
+
+namespace DefaultNamespace {
+    using System.Threading;
+    using System;
+    using System.IO;
+
+    public class ThdTreeLivingObj {
+
+        public static int Main (System.String[] Args)
+        {
+            Console.Out.WriteLine("Test should return with ExitCode 100 ...");
+            // console out sync Console.SetOut(TextWriter.Synchronized(Console.Out));
+
+            int iNofThread = 0;
+
+            if (Args.Length == 1)
+            {
+                if (!Int32.TryParse( Args[0], out iNofThread ))
+                {
+                    iNofThread = 2;
+                }
+            }
+            else
+            {
+                iNofThread = 2;
+            }
+
+            int[] count = {1000, 1000, 1000, -900, 0, 700, 100};
+            TreeThread Mv_TreeThread;
+            for (int i = 0; i < iNofThread; i++)
+            {
+                Mv_TreeThread = new TreeThread(i, TreeType.Living, count);
+            }
+            return 100;
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/BinTree/thdtreelivingobj.csproj b/src/coreclr/tests/src/GC/Scenarios/BinTree/thdtreelivingobj.csproj
new file mode 100644 (file)
index 0000000..8849ad7
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="ThdTreeLivingObj.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="BinTree.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/BinTree/treethread.cs b/src/coreclr/tests/src/GC/Scenarios/BinTree/treethread.cs
new file mode 100644 (file)
index 0000000..ba14af5
--- /dev/null
@@ -0,0 +1,50 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace DefaultNamespace {
+    using System.Threading;
+    using System;
+    using System.IO;
+
+    public class TreeThread {
+
+        internal int[] mA_Count;
+        internal int m_id = 0;
+        internal BinTree m_BinTree;
+        internal Thread Mv_Thread;
+
+        public TreeThread(int ThreadId, TreeType treeType, int[] count)
+        {
+            // attempt to synchronize the console output
+            //Console.SetOut(TextWriter.Synchronized(Console.Out));
+
+            mA_Count = count;
+            m_BinTree = new BinTree(ThreadId, treeType);
+            m_id = ThreadId;
+            Mv_Thread = new Thread( new ThreadStart(this.ThreadStart));
+            Mv_Thread.Start( );
+            Console.Out.WriteLine("Started Thread: " + m_id);
+        }
+
+        public void ThreadStart()
+        {                                           //All threads start here
+            for (int i = 0; i < mA_Count.Length; i++)
+            {
+                if (mA_Count[i] == 0)
+                {
+                    m_BinTree.Empty(m_id);
+                }
+                else if (mA_Count[i] > 0 )
+                {
+                    m_BinTree.AddNodes(mA_Count[i], m_id);
+                }
+                else
+                {
+                    m_BinTree.DeleteNodes((mA_Count[i] * -1), m_id);
+                }
+            }
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/arrcpy.cs b/src/coreclr/tests/src/GC/Scenarios/Boxing/arrcpy.cs
new file mode 100644 (file)
index 0000000..118a5bd
--- /dev/null
@@ -0,0 +1,58 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace DefaultNamespace {
+    using System;
+
+    internal class ArrCpy
+    {
+        public static int Main(String [] str)
+        {
+            int iSize = 100;
+            int iRep = 10;
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            ArrCpy mv_obj = new ArrCpy();
+            Object [] ObjAry = new Object[iSize];
+            for( int j=0; j< iRep; j++ )
+            {
+                for(int i=0; i< iSize; i++)
+                {
+                    if( i==0 )
+                        ObjAry[i] = new int[1];
+                    else if( i==1 )
+                        ObjAry[i] = new Object[i];
+                    else
+                        ObjAry[i] = mv_obj.CreatAry( i-1, ObjAry );
+                }
+                GC.Collect();
+            }
+            return 100;
+
+        }
+
+
+        public Object CreatAry( int iSize, Object [] ObjAry)
+        {
+            Object [] ary = new Object[iSize];
+            if( ary.Length > 1 )
+            {
+                Array.Copy( ObjAry, ary, ary.Length-2 );
+                if( ary.Length-1 == 1 )
+                {
+                    ary[ary.Length-1] = new byte[ary.Length];
+                }
+                else
+                {
+                    ary[ary.Length-1] = CreatAry( ary.Length-1, ary );
+                }
+            }
+            else
+            {
+                ary[0] = new Object[0];
+            }
+            return ary;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/arrcpy.csproj b/src/coreclr/tests/src/GC/Scenarios/Boxing/arrcpy.csproj
new file mode 100644 (file)
index 0000000..8a6b60d
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="ArrCpy.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
index baebb05..28d5fc9 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant.cs b/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant.cs
new file mode 100644 (file)
index 0000000..445c70f
--- /dev/null
@@ -0,0 +1,205 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace GCVariant {
+    using System;
+
+    internal class GCVariant
+    {
+
+        internal static object [] G_Vart;
+
+        public static int Main(String [] Args)
+        {
+            int iRep = 0;
+            int iObj = 0;
+            int iNum = 0;
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            switch( Args.Length )
+            {
+                case 1:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 5;
+                    }
+                    iObj = 100;
+                    iNum = 10;
+                break;
+
+                case 2:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 5;
+                    }
+                    if (!Int32.TryParse( Args[1], out iObj ))
+                    {
+                        iObj = 100;
+                    }
+                    iNum = 10;
+                break;
+
+                case 3:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 5;
+                    }
+                    if (!Int32.TryParse( Args[1], out iObj ))
+                    {
+                        iObj = 100;
+                    }
+                    if (!Int32.TryParse( Args[2], out iNum ))
+                    {
+                        iNum = 10;
+                    }
+                break;
+
+                default:
+                    iRep = 5;
+                    iObj = 100;
+                    iNum = 10;
+                break;
+            }
+
+           
+            Console.Write("iRep= ");
+            Console.Write(iRep);
+            Console.Write(" iObj= ");
+            Console.Write(iObj);
+            Console.Write(" iNum= ");
+            Console.WriteLine(iNum);
+
+            GCVariant Mv_Obj = new GCVariant();
+
+            if(Mv_Obj.runTest(iRep, iObj, iNum ))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            Console.WriteLine("Test Failed");
+            return 1;
+        }
+
+
+        public bool runTest(int iRep, int iObj, int iNum)
+        {
+            DoubLink L_Node1 = new DoubLink(iNum);
+            DLinkNode L_Node2 = new DLinkNode(iNum, null, null);
+
+            for(int i= 0; i< iRep; i++)
+            {
+                G_Vart = new Object[iObj];
+                for(int j=0; j< iObj; j++)
+                {
+                    if(j%2 == 1)
+                        G_Vart[j] = (L_Node1);
+                    else
+                        G_Vart[j] = (L_Node2);
+                }
+                MakeLeak(iRep, iObj, iNum);
+
+            }
+            return true;
+        }
+
+
+        public void MakeLeak(int iRep, int iObj, int iNum)
+        {
+            DoubLink L_Node1 = new DoubLink(iNum);
+            DLinkNode L_Node2 = new DLinkNode(iNum, null, null);
+            Object [] L_Vart1 = new Object[iObj];
+            Object [] L_Vart2;
+
+            for(int i= 0; i< iRep; i++)
+            {
+                L_Vart2 = new Object[iObj];
+                for(int j=0; j< iObj; j++)
+                {
+                    if(j%2 == 1)
+                    {
+                        L_Vart1[j] = (j);
+                        L_Vart2[j] = ((double)j);
+                    }
+                    else
+                    {
+                        L_Vart2[j] = (L_Node2);
+                        L_Vart1[j] = (L_Node1);
+                    }
+                }
+            }
+        }
+    }
+
+    public class DoubLink
+    {
+        internal DLinkNode[] Mv_DLink;
+
+        public DoubLink(int Num)
+            : this(Num, false)
+        {
+        }
+
+        public DoubLink(int Num, bool large)
+        {
+
+            Mv_DLink = new DLinkNode[Num];
+
+            if (Num == 0)
+            {
+                return;
+            }
+
+            if (Num == 1)
+            {
+                // only one element
+                Mv_DLink[0] = new DLinkNode((large ? 256 : 1), Mv_DLink[0], Mv_DLink[0]);
+                return;
+            }
+
+            // first element
+            Mv_DLink[0] = new DLinkNode((large ? 256 : 1), Mv_DLink[Num - 1], Mv_DLink[1]);
+
+            // all elements in between
+            for (int i = 1; i < Num - 1; i++)
+            {
+                Mv_DLink[i] = new DLinkNode((large ? 256 : i + 1), Mv_DLink[i - 1], Mv_DLink[i + 1]);
+            }
+
+            // last element
+            Mv_DLink[Num - 1] = new DLinkNode((large ? 256 : Num), Mv_DLink[Num - 2], Mv_DLink[0]);
+        }
+
+
+        public int NodeNum
+        {
+            get
+            {
+                return Mv_DLink.Length;
+            }
+        }
+
+
+    }
+
+    public class DLinkNode
+    {
+        // disabling unused variable warning
+#pragma warning disable 0414
+        internal DLinkNode Last;
+        internal DLinkNode Next;
+#pragma warning restore 0414
+
+        internal int[] Size;
+
+        public DLinkNode(int SizeNum, DLinkNode LastObject, DLinkNode NextObject)
+        {
+            Last = LastObject;
+            Next = NextObject;
+            Size = new int[SizeNum * 1024];
+            Size[0] = 1;
+            Size[SizeNum * 1024 - 1] = 2;
+        }
+    }
+
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant.csproj b/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant.csproj
new file mode 100644 (file)
index 0000000..5df1201
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="GCVariant.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant2.cs b/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant2.cs
new file mode 100644 (file)
index 0000000..1c126a8
--- /dev/null
@@ -0,0 +1,112 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**************************************************************
+/*This tests covered asigning all basic types to Objects
+/*Delete the reference of Varaints from Object arrays/Object
+/*to see if GC can work fine with them. The most of Object Object's
+/*lifetime is shorter than theirs in GCObject3.
+/**************************************************************/
+
+namespace DefaultNamespace {
+    using System;
+
+    internal class GCVariant2
+    {
+        internal Object [] G_Vart;
+        public static int Main(String [] Args)
+        {
+            int iRep = 0;
+            int iObj = 0;
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            switch( Args.Length )
+            {
+                case 1:
+                    Int32.TryParse( Args[0], out iRep);
+                goto default;
+                case 2:
+                    if (!Int32.TryParse( Args[0], out iRep))
+                    {
+                        goto default;
+                    }
+                    Int32.TryParse( Args[1], out iObj);
+                goto default;
+                default:
+                    if (iRep == 0)
+                        iRep = 10;
+                    if (iObj == 0)
+                        iObj = 40000;
+                break;
+            }
+
+            Console.Write("iRep= ");
+            Console.Write(iRep);
+            Console.Write(" ; iObj= ");
+            Console.WriteLine(iObj);
+
+            GCVariant2 Mv_Obj = new GCVariant2();
+            if(Mv_Obj.runTest(iRep, iObj ))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+
+            Console.WriteLine("Test Failed");
+            return 1;
+        }
+
+
+        public bool runTest(int iRep, int iObj)
+        {
+            Object TmpV;
+
+            for(int i= 0; i< iRep; i++)
+            {
+                G_Vart = new Object[iObj];
+                for(int j=0; j< iObj; j++)
+                {
+                    switch(j%8)
+                    {
+                        case 0:
+                            G_Vart[j] = (j);
+                            TmpV = (j);
+                        break;
+                        case 1:
+                            G_Vart[j] = (true);
+                            TmpV = (false);
+                        break;
+                        case 2:
+                            G_Vart[j] = ((float)j/3);
+                            TmpV = ((float)j/3);
+                        break;
+                        case 3:
+                            G_Vart[j] = ((byte)j);
+                            TmpV = ((byte)j);
+                        break;
+                        case 4:
+                            G_Vart[j] = ((short)j);
+                            TmpV = ((short)j);
+                        break;
+                        case 5:
+                            G_Vart[j] = ((long)j);
+                            TmpV = ((long)j);
+                        break;
+                        case 6:
+                            G_Vart[j] = ((double)j/0.33);
+                            TmpV = ((double)j/0.33);
+                        break;
+                        case 7:
+                            G_Vart[j] = ((char)j);
+                            TmpV = ((char)j);
+                        break;
+
+                    }
+                }
+                GC.Collect();
+            }
+            return true;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant2.csproj b/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant2.csproj
new file mode 100644 (file)
index 0000000..cc533d8
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="GCVariant2.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant3.cs b/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant3.cs
new file mode 100644 (file)
index 0000000..8382cd0
--- /dev/null
@@ -0,0 +1,156 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**************************************************************
+/*This tests covered asigning all basic types to Variants
+/*and converting Variants to basic types. Delete the reference
+/*of Varaints from Variant arrays to see if GC can work fine
+/*with them. Because this test using Variant to save Variant
+/*the Variant Object's life time is longer than theirs in GCVariant2
+/**************************************************************/
+
+namespace DefaultNamespace {
+    using System;
+
+    internal class GCVariant3
+    {
+
+// disabling unused variable warning
+#pragma warning disable 0414
+        internal Object [] G_Vart1;
+        internal Object [] G_Vart2;
+        internal Object [] G_Vart3;
+        internal Object [] G_Vart4;
+        internal Object [] G_Vart5;
+        internal Object [] G_Vart6;
+#pragma warning restore 0414
+
+        public static int Main(String [] Args)
+        {
+            int iRep = 0;
+            int iObj = 0;
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            switch( Args.Length )
+            {
+                case 1:
+                    Int32.TryParse( Args[0], out iRep);
+                goto default;
+                case 2:
+                    if (!Int32.TryParse( Args[0], out iRep))
+                    {
+                        goto default;
+                    }
+                    Int32.TryParse( Args[1], out iObj);
+                goto default;
+                default:
+                    if (iRep == 0)
+                        iRep = 10;
+                    if (iObj == 0)
+                        iObj = 40000;
+                break;
+            }
+
+            Console.Write("iRep= ");
+            Console.Write(iRep);
+            Console.Write(" ; iObj= ");
+            Console.WriteLine(iObj );
+            GCVariant3 Mv_Obj = new GCVariant3();
+            if(Mv_Obj.runTest(iRep, iObj ))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+
+            Console.WriteLine("Test Failed");
+            return 1;
+        }
+
+        public bool runTest(int iRep, int iObj)
+        {
+
+            G_Vart2 = new Object[iObj];
+            G_Vart3 = new Object[iObj];
+            G_Vart4 = new Object[iObj];
+            G_Vart5 = new Object[iObj];
+
+            int iTmp;
+            bool bTmp;
+            long lTmp;
+            double dTmp;
+            byte btTmp;
+            short sTmp;
+            char cTmp;
+            float fTmp;
+            for(int i= 0; i< iRep; i++)
+            {
+                G_Vart1 = new Object[iObj];
+                G_Vart6 = new Object[iObj];
+                for(int j=0; j< iObj; j++)
+                {
+                    switch(j%8)
+                    {
+                        case 0:
+                            G_Vart1[j] = (j);
+                            G_Vart2[j] = ((char)j);
+                            iTmp = (int)G_Vart1[j];
+                            G_Vart3[j] = (iTmp);
+
+                        break;
+                        case 1:
+                            G_Vart1[j] = (true);
+                            G_Vart2[j]= ((double)j/0.33);
+                            bTmp = (bool)G_Vart1[j] ;
+                            G_Vart3[j] = (bTmp);
+
+                        break;
+                        case 2:
+                            G_Vart1[j] = ((float)j/3);
+                            G_Vart2[j] = ((long)j);
+                            fTmp = (float)G_Vart1[j] ;
+                            G_Vart3[j] = (fTmp);
+                        break;
+                        case 3:
+                            G_Vart1[j] = ((byte)j);
+                            G_Vart2[j] = ((short)j);
+                            btTmp = (byte)G_Vart1[j] ;
+                            G_Vart3[j] = (btTmp);
+                        break;
+                        case 4:
+                            G_Vart1[j] = ((short)j);
+                            char[] carr= new char[1];
+                            carr[0] = (char)j;
+                            G_Vart2[j] = new string(carr);
+                            sTmp = (short)G_Vart1[j]  ;
+                            G_Vart3[j] = (sTmp);
+                        break;
+                        case 5:
+                            G_Vart1[j] = ((long)j);
+                            G_Vart2[j] = ((double)j/0.33);;
+                            lTmp = (long)G_Vart1[j]  ;
+                            G_Vart3[j] = (lTmp);
+                        break;
+                        case 6:
+                            G_Vart1[j] = ((double)j/0.33);
+                            G_Vart2[j] = ((char)j);
+                            dTmp = (double)G_Vart1[j] ;
+                            G_Vart3[j] = (dTmp);
+                        break;
+                        case 7:
+                            G_Vart1[j] = ((char)j);
+                            G_Vart2[j] = ((float)j/3);
+                            cTmp = (char)G_Vart1[j]  ;
+                            G_Vart3[j] = (cTmp);
+                        break;
+
+                    }
+
+                }
+                GC.Collect();
+            }
+            return true;
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant3.csproj b/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant3.csproj
new file mode 100644 (file)
index 0000000..a53ea2b
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="GCVariant3.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant4.cs b/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant4.cs
new file mode 100644 (file)
index 0000000..6943c4b
--- /dev/null
@@ -0,0 +1,142 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**************************************************************
+/*This tests' porpuse is to test GC with local Object objects
+/*This tests covered asigning all basic types to Objects
+/*and converting Objects to basic types. Delete the reference
+/*of Objects from Object arrays and make local objects of Object
+/*in MakeLeak() see if GC can work fine
+/**************************************************************/
+
+namespace DefaultNamespace {
+    using System;
+
+    internal class GCVariant4
+    {
+        internal Object [] G_Vart1;
+        internal Object [] G_Vart3;
+
+        public static int Main(String [] Args)
+        {
+            int iRep = 0;
+            int iObj = 0;
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            switch( Args.Length )
+            {
+                case 1:
+                    Int32.TryParse( Args[0], out iRep);
+                goto default;
+                case 2:
+                    if (!Int32.TryParse( Args[0], out iRep))
+                    {
+                        goto default;
+                    }
+                    Int32.TryParse( Args[1], out iObj);
+                goto default;
+                default:
+                    if (iRep == 0)
+                        iRep = 10;
+                    if (iObj == 0)
+                        iObj = 400;
+                break;
+            }
+
+            Console.Write("iRep= ");
+            Console.Write(iRep);
+            Console.Write(" ; iObj= ");
+            Console.WriteLine(iObj);
+
+            GCVariant4 Mv_Obj = new GCVariant4();
+            if(Mv_Obj.runTest(iRep, iObj ))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+
+            Console.WriteLine("Test Failed");
+            return 1;
+        }
+
+
+        public bool runTest(int iRep, int iObj)
+        {
+            G_Vart3 = new Object[iObj];
+
+            for(int i= 0; i< iRep; i++)
+            {
+                G_Vart1 = new Object[iObj];
+                for(int j=0; j< iObj; j++)
+                {
+                    switch(j%8)
+                    {
+                        case 0:
+                            G_Vart1[j] = (j);
+                            G_Vart3[j] = (int)(G_Vart1[j]);
+
+                        break;
+                        case 1:
+                            G_Vart1[j] = (true);
+                            G_Vart3[j] = (bool)(G_Vart1[j]);
+
+                        break;
+                        case 2:
+                            G_Vart1[j] = ((float)j/3);
+                            G_Vart3[j] = (float)(G_Vart1[j]);
+                        break;
+                        case 3:
+                            G_Vart1[j] = ((byte)j);
+                            G_Vart3[j] = (byte)(G_Vart1[j]);
+                        break;
+                        case 4:
+                            G_Vart1[j] = ((short)j);
+                            G_Vart3[j] = (short)(G_Vart1[j]);
+                        break;
+                        case 5:
+                            G_Vart1[j] = ((long)j);
+                            G_Vart3[j] = (long)(G_Vart1[j]);
+                        break;
+                        case 6:
+                            G_Vart1[j] = ((double)j/0.33);
+                            G_Vart3[j] = (double)(G_Vart1[j]);
+                        break;
+                        case 7:
+                            G_Vart1[j] = ((char)j);
+                            G_Vart3[j] = (char)(G_Vart1[j]);
+                        break;
+
+                    }
+                    MakeLeak(j);
+                }
+                GC.Collect();
+                
+            }
+
+            return true;
+        }
+
+
+        public void MakeLeak(int value)
+        {
+            int iTmp = value;
+            bool bTmp = true;
+            long lTmp = (long)value;
+            double dTmp = (double)value*0.0035;
+            byte btTmp = (byte)value;
+            short sTmp = (short)value;
+            char cTmp = (char)value;
+            float fTmp = (float)value/99;
+            Object V1 = (iTmp);
+            Object V2 = (bTmp);
+            Object V3 = (lTmp);
+            Object V4 = (dTmp);
+            Object V5 = (btTmp);
+            Object V6 = (sTmp);
+            Object V7 = (cTmp);
+            Object V8 = (fTmp);
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant4.csproj b/src/coreclr/tests/src/GC/Scenarios/Boxing/gcvariant4.csproj
new file mode 100644 (file)
index 0000000..9aa256b
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="GCVariant4.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/project.json b/src/coreclr/tests/src/GC/Scenarios/Boxing/project.json
deleted file mode 100644 (file)
index 14c11d2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "dependencies": {
-    "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
-    "System.Collections": "4.0.10",
-    "System.Collections.NonGeneric": "4.0.1-beta-23302",
-    "System.Collections.Specialized": "4.0.1-beta-23302",
-    "System.ComponentModel": "4.0.1-beta-23302",
-    "System.Console": "4.0.0-beta-23302",
-    "System.Diagnostics.Process": "4.0.0-beta-23302",
-    "System.Globalization": "4.0.10",
-    "System.Globalization.Calendars": "4.0.0",
-    "System.IO": "4.0.10",
-    "System.IO.FileSystem": "4.0.0",
-    "System.IO.FileSystem.Primitives": "4.0.0",
-    "System.Linq": "4.0.1-beta-23302",
-    "System.Linq.Queryable": "4.0.1-beta-23302",
-    "System.Reflection": "4.0.10",
-    "System.Reflection.Primitives": "4.0.0",
-    "System.Runtime": "4.0.20",
-    "System.Runtime.Extensions": "4.0.10",
-    "System.Runtime.Handles": "4.0.0",
-    "System.Runtime.InteropServices": "4.0.20",
-    "System.Runtime.Loader": "4.0.0-beta-23302",
-    "System.Text.Encoding": "4.0.10",
-    "System.Threading": "4.0.10",
-    "System.Xml.ReaderWriter": "4.0.11-beta-23302",
-    "System.Xml.XDocument": "4.0.11-beta-23302",
-    "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
-  },
-  "frameworks": {
-    "dnxcore50": {}
-  }
-}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/simpvariant.cs b/src/coreclr/tests/src/GC/Scenarios/Boxing/simpvariant.cs
new file mode 100644 (file)
index 0000000..6d703e5
--- /dev/null
@@ -0,0 +1,97 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// Basic Object Test that uses tests the following types:
+//  int
+//  long
+//  String
+//  float
+// as Objects. This is very Basic - uses arrays of 500 and if it does not crash
+// that is a valid test pass.
+//
+
+
+namespace DefaultNamespace {
+    using System;
+
+    public class SimpObject
+    {
+        public static int Main ()
+        {
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+            SimpObject sv = new SimpObject( );
+            sv.RunTest( );
+            return 100;
+        }
+
+        public void RunTest()
+        {
+            int Size = 500;
+
+            Console.WriteLine( "Simple Object GC Test" );
+            Console.WriteLine( "Starting int & String Test..." );
+
+            Object [] tempArray = new Object[ Size ];
+
+            for( int i = 0; i < Size; i++ )
+            {
+                if( i % 2 == 1 )
+                {
+                    tempArray[i] = i;
+                }
+                else
+                {
+                    char[] carr = new char[1];
+                    carr[0] = (char)i;
+                    tempArray[i] = new string(carr);
+                }
+
+                GC.Collect( );
+            }
+
+            tempArray = null;
+
+            GC.Collect( );
+
+            Console.WriteLine( "int & String Test Complete." );
+            Console.WriteLine();
+            Console.WriteLine( "Starting float, long, & String Test..." );
+
+            tempArray = new Object[ Size ];
+
+            for( int i = 0; i < Size; i++ )
+            {
+                if( i % 2 == 1 )
+                {
+
+                    if( i < Size / 2 )
+                    {
+                        float foo = i;
+                        tempArray[ i ] = foo;
+                    }
+                    else
+                    {
+                        long foo = i;
+                        tempArray[ i ] = foo;
+                    }
+                }
+                else
+                {
+                    char[] carr = new char[1];
+                    carr[0] = (char)i;
+                    tempArray[i] = new string(carr);
+                }
+
+                GC.Collect( );
+            }
+
+            tempArray = null;
+
+            GC.Collect( );
+
+            Console.WriteLine( "float, long, & String Test complete." );
+
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/simpvariant.csproj b/src/coreclr/tests/src/GC/Scenarios/Boxing/simpvariant.csproj
new file mode 100644 (file)
index 0000000..81166fc
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="SimpVariant.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/vararystress.cs b/src/coreclr/tests/src/GC/Scenarios/Boxing/vararystress.cs
new file mode 100644 (file)
index 0000000..47da06a
--- /dev/null
@@ -0,0 +1,75 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**************************************************************/
+/* Test: VarAryStress
+/* Coverage:    Test GC and Variant Array
+/* What:    Use SetVarAry method that calls himself to generate
+/* Variant array elements. The elements are Variant arrays whose
+/* elememts also are Variant array. iRep is the max embeded level
+/* number of these Variant array. Check out if GC can handle these
+/* objects
+/**************************************************************/
+
+namespace DefaultNamespace {
+    using System;
+
+    internal class VarAryStress
+    {
+        public static int Main( String [] args )
+        {
+            int iRep = 20;
+
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            if( args.Length > 0 )
+            {
+                try
+                {
+                    iRep = Int32.Parse( args[0] );
+                }
+                catch(FormatException )
+                {
+                    Console.WriteLine("FormatException is caught");
+                }
+            }
+
+            Object [] VarAry = new Object[1];
+            VarAryStress mv_obj = new VarAryStress();
+            for(int i=0; i< iRep; i++ )
+            {
+                if( i>1 )
+                {
+                    VarAry[0] = mv_obj.SetVarAry( i-1 );
+                }
+                else
+                {
+                    VarAry[0] = i;
+                }
+                if( i%5 == 0)
+                {
+                    GC.Collect();
+                    // Console.WriteLine( "HeapSize after GC: {0}", GC.GetTotalMemory(false) );
+                }
+
+            }
+
+            Console.WriteLine( "Test Passed" );
+            return 100;
+        }
+
+        public Object SetVarAry( int iSize )
+        {
+            Object [] vary= new Object[2];
+            for( int i=0; i< iSize; i++ )
+            {
+                if( i > 1 )
+                    vary[0] = SetVarAry( i-1 );
+                else
+                    vary[1] = i;
+            }
+            return vary;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/vararystress.csproj b/src/coreclr/tests/src/GC/Scenarios/Boxing/vararystress.csproj
new file mode 100644 (file)
index 0000000..2a111f4
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="VarAryStress.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/variantint.cs b/src/coreclr/tests/src/GC/Scenarios/Boxing/variantint.cs
new file mode 100644 (file)
index 0000000..03e12f3
--- /dev/null
@@ -0,0 +1,94 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**
+ * Description:
+ *  A Test which tests the GC using Variants. It is a test which creates a bunch of Variant Objects
+ *  with mainly INT datatype.
+*/
+
+namespace DefaultNamespace {
+    using System;
+
+    internal class VariantInt
+    {
+
+        internal Object [] m_aVar;
+        internal Object [] m_aVar1;
+
+        public static int Main(String [] Args)
+        {
+            int iRep = 0;
+            int iObj = 0;
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            if (Args.Length==2)
+            {
+                if (!Int32.TryParse( Args[0], out iRep ) ||
+                    !Int32.TryParse( Args[0], out iObj ))
+                {
+                    iRep = 20;
+                    iObj = 100;
+                }
+            }
+            else
+            {
+                iRep = 20;
+                iObj = 100;
+            }
+
+            VariantInt Mv_Obj = new VariantInt();
+            if(Mv_Obj.runTest(iRep, iObj))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            Console.WriteLine("Test Failed");
+            return 1;
+        }
+
+
+        public bool runTest(int iRep, int iObj)
+        {
+            for(int i = 0; i < iRep; i++)
+            {
+                m_aVar = new Object[iObj];
+                for(int j = 0; j < iObj; j++)
+                {
+                    if(j%2 == 1)
+                    {
+                        m_aVar[j] = i;
+                    }
+                    else
+                    {
+                        m_aVar[j] = null;
+                    }
+                }
+                MakeLeak(iRep, iObj);
+                Console.WriteLine(i);
+            }
+            return true;
+        }
+
+
+        public void MakeLeak(int iRep, int iObj)
+        {
+            Object [] L_Vart1 = new Object[iObj];
+            Object [] L_Vart2;
+            m_aVar1 = new Object[iObj];
+            for(int i = 0; i < iRep; i++)
+            {
+                L_Vart2 = new Object[iObj];
+                for(int j=0; j< iObj; j++)
+                {
+                    L_Vart1[j] = m_aVar[j];
+                    L_Vart2[j] = (m_aVar[j]);
+                    m_aVar1[j] = (new int[10]);
+                    m_aVar1[j] = (m_aVar[j]);
+                }
+            }
+            m_aVar1 = null;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/variantint.csproj b/src/coreclr/tests/src/GC/Scenarios/Boxing/variantint.csproj
new file mode 100644 (file)
index 0000000..4b06f35
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="VariantInt.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/variantlinklist.cs b/src/coreclr/tests/src/GC/Scenarios/Boxing/variantlinklist.cs
new file mode 100644 (file)
index 0000000..7801d2a
--- /dev/null
@@ -0,0 +1,106 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**
+ * Description:
+ *      Mainly stresses the GC by creating a link list of Variants. A large number
+ *      of nodes are created and leaks generated by traversing the link list and changing
+ *      the variant objects in the nodes
+ */
+
+
+namespace DefaultNamespace {
+    using System;
+
+    internal class Node
+    {
+// disabling unused variable warning
+#pragma warning disable 0414
+        internal Object m_Var;
+#pragma warning restore 0414
+
+        internal Object [] m_aVar;
+        internal Node next;
+
+        public Node()
+        {
+            m_aVar = new Object[10];
+            m_aVar[0] = 10;
+            m_aVar[1] = ("ABC");
+        }
+    }
+
+    internal class VariantLinkList
+    {
+        internal Node m_Root;
+
+        public static int Main(String [] Args){
+        int iRep = 0;
+        int iObj = 0;
+        Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            if (Args.Length==2)
+            {
+                if (!Int32.TryParse( Args[0], out iRep ) ||
+                    !Int32.TryParse( Args[0], out iObj ))
+                {
+                    iRep = 40000;
+                    iObj = 100;
+                }
+            }
+            else
+            {
+                iRep = 40000;
+                iObj = 100;
+            }
+
+            VariantLinkList Mv_Obj = new VariantLinkList();
+            if(Mv_Obj.runTest(iRep, iObj))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            Console.WriteLine("Test Failed");
+            return 1;
+        }
+
+        public bool runTest(int iRep, int iObj)
+        {
+            m_Root = new Node();
+            m_Root.m_Var = null;
+            m_Root.next = null;
+            Node temp = m_Root;
+            for(int i = 0; i < iRep; i++)
+            {
+                temp.next = new Node();
+                temp = temp.next;
+                temp.m_Var = (i);
+                temp.next = null;
+                if ((i+1)%10000 == 0)
+                {
+                    Console.Write("Nodes Created: ");
+                    Console.WriteLine(i+1);
+                }
+            }
+            temp = m_Root;
+            m_Root = null;
+
+            Console.WriteLine("Done creating");
+
+            for(int i = 0; i < iRep; i++)
+            {
+                temp = temp.next;
+                if ((i+1)%10000 == 0)
+                {
+                    Console.Write("Nodes Traversed: ");
+                    Console.WriteLine(i + 1);
+                    GC.Collect();
+                }
+            }
+            GC.Collect();
+            return true;
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Boxing/variantlinklist.csproj b/src/coreclr/tests/src/GC/Scenarios/Boxing/variantlinklist.csproj
new file mode 100644 (file)
index 0000000..f0575ce
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="VariantLinkList.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
index 8d6a154..6076046 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
index baebb05..28d5fc9 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlbigleak.cs b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlbigleak.cs
new file mode 100644 (file)
index 0000000..c72c8c0
--- /dev/null
@@ -0,0 +1,199 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/******************************************************************
+/*Test case for testing GC with cyclic double linked list leaks
+/*It's based on DoubLinkGen, the deference is its base node has 1MB
+/*memory, the nodes number inside of every cyclic double linked list
+/*is iObj.
+/******************************************************************/
+
+
+namespace DoubLink {
+    using System;
+
+    public class DLBigLeak
+    {
+        internal DoubLink[] Mv_Doub;
+
+        public static int Main(System.String [] Args)
+        {
+            int iRep = 0;
+            int iObj = 0;
+
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+            switch( Args.Length )
+            {
+                case 1:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 5;
+                    }
+                break;
+
+                case 2:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 5;
+                    }
+                    if (!Int32.TryParse( Args[1], out iObj ))
+                    {
+                        iObj = 30;
+                    }
+                break;
+
+                default:
+                    iRep = 5;
+                    iObj = 30;
+                break;
+
+            }
+
+            DLBigLeak Mv_Leak = new DLBigLeak();
+            if(Mv_Leak.runTest(iRep, iObj ))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+
+            Console.WriteLine("Test Failed");
+            return 1;
+
+        }
+
+
+        public bool runTest(int iRep, int iObj)
+        {
+            Mv_Doub = new DoubLink[iRep];
+            for(int i=0; i<10; i++)
+            {
+                SetLink(iRep, iObj);
+                MakeLeak(iRep);
+                GC.Collect();
+            }
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            Console.Write(DLinkNode.FinalCount);
+            Console.WriteLine(" DLinkNodes finalized");
+            return (DLinkNode.FinalCount==iRep*iObj*10);
+        }
+
+
+        public void SetLink(int iRep, int iObj)
+        {
+
+            for(int i=0; i<iRep; i++)
+            {
+                Mv_Doub[0] = new DoubLink(iObj, true);
+                GC.Collect();
+            }
+
+        }
+
+
+        public void MakeLeak(int iRep)
+        {
+
+            for(int i=0; i<iRep; i++)
+            {
+                Mv_Doub[i] = null;
+            }
+
+        }
+
+    }
+
+    public class DoubLink
+    {
+        internal DLinkNode[] Mv_DLink;
+
+        public DoubLink(int Num)
+            : this(Num, false)
+        {
+        }
+
+        public DoubLink(int Num, bool large)
+        {
+
+            Mv_DLink = new DLinkNode[Num];
+
+            if (Num == 0)
+            {
+                return;
+            }
+
+            if (Num == 1)
+            {
+                // only one element
+                Mv_DLink[0] = new DLinkNode((large ? 250 : 1), Mv_DLink[0], Mv_DLink[0]);
+                return;
+            }
+
+            // first element
+            Mv_DLink[0] = new DLinkNode((large ? 250 : 1), Mv_DLink[Num - 1], Mv_DLink[1]);
+
+            // all elements in between
+            for (int i = 1; i < Num - 1; i++)
+            {
+                Mv_DLink[i] = new DLinkNode((large ? 250 : i + 1), Mv_DLink[i - 1], Mv_DLink[i + 1]);
+            }
+
+            // last element
+            Mv_DLink[Num - 1] = new DLinkNode((large ? 250 : Num), Mv_DLink[Num - 2], Mv_DLink[0]);
+        }
+
+
+        public int NodeNum
+        {
+            get
+            {
+                return Mv_DLink.Length;
+            }
+        }
+
+
+        public DLinkNode this[int index]
+        {
+            get
+            {
+                return Mv_DLink[index];
+            }
+
+            set
+            {
+                Mv_DLink[index] = value;
+            }
+        }
+
+    }
+
+    public class DLinkNode
+    {
+        // disabling unused variable warning
+#pragma warning disable 0414
+        internal DLinkNode Last;
+        internal DLinkNode Next;
+        internal int[] Size;
+#pragma warning restore 0414
+
+        public static int FinalCount = 0;
+
+        public DLinkNode(int SizeNum, DLinkNode LastObject, DLinkNode NextObject)
+        {
+            Last = LastObject;
+            Next = NextObject;
+            Size = new int[SizeNum * 1024];
+        }
+
+        ~DLinkNode()
+        {
+            FinalCount++;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlbigleak.csproj b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlbigleak.csproj
new file mode 100644 (file)
index 0000000..fa08252
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="dLBigleak.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlbigleakthd.cs b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlbigleakthd.cs
new file mode 100644 (file)
index 0000000..f1a322a
--- /dev/null
@@ -0,0 +1,149 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/******************************************************************
+/*Test case for testing GC with cyclic double linked list leaks
+/*It's based on DoubLinkGen, the deference is its base node has 1MB
+/*memory, the nodes number inside of every cyclic double linked list
+/*is iObj.
+/******************************************************************/
+
+namespace DoubLink {
+    using System.Threading;
+    using System;
+    using System.IO;
+
+    public class DLBigLeakThd
+    {
+        internal DoubLink []Mv_Doub;
+        internal int iRep = 0;
+        internal int iObj = 0;
+
+        public static int Main(System.String [] Args)
+        {
+            DLBigLeakThd Mv_Leak = new DLBigLeakThd();
+
+            int iRep = 0;
+            int iObj = 0;
+            int iThd = 0;
+            Console.Out.WriteLine("Test should return with ExitCode 100 ...");
+            //Console.SetOut(TextWriter.Synchronized(Console.Out));
+
+            switch( Args.Length )
+            {
+                case 1:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 1;
+                    }
+                break;
+
+                case 2:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 1;
+                    }
+                    if (!Int32.TryParse( Args[1], out iObj ))
+                    {
+                        iObj = 20;
+                    }
+                break;
+
+                case 3:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 1;
+                    }
+                    if (!Int32.TryParse( Args[1], out iObj ))
+                    {
+                        iObj = 20;
+                    }
+                    if (!Int32.TryParse( Args[2], out iThd ))
+                    {
+                        iThd = 2;
+                    }
+                break;
+
+                default:
+                    iRep = 1;
+                    iObj = 20;
+                    iThd = 2;
+                break;
+            }
+
+            if (Mv_Leak.runTest(iRep, iObj, iThd ))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            Console.WriteLine("Test Failed");
+            return 1;
+
+        }
+
+
+        public bool runTest(int iRep, int iObj, int iThd)
+        {
+            this.iRep = iRep;
+            this.iObj = iObj;
+            Mv_Doub = new DoubLink[iRep];
+            Thread [] Mv_Thread = new Thread[iThd];
+            for(int i=0; i<iThd; i++)
+            {
+                Mv_Thread[i] = new Thread(new ThreadStart(this.ThreadStart));
+                Mv_Thread[i].Start( );
+            }
+            for(int i=0; i<20; i++)
+            {
+                SetLink(iRep, iObj);
+                MakeLeak(iRep);
+            }
+            for(int i=0; i<iThd; i++)
+            {
+                Mv_Thread[i].Join();
+            }
+
+            Mv_Doub = null;
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+
+            int goal = iRep*15*iThd*iObj+20*iRep*iObj;
+            Console.WriteLine("{0}/{1} DLinkNodes finalized", DLinkNode.FinalCount, goal);
+            return (DLinkNode.FinalCount==goal);
+        }
+
+
+        public void SetLink(int iRep, int iObj)
+        {
+
+            for(int i=0; i<iRep; i++)
+            {
+                Mv_Doub[i] = new DoubLink(iObj, true);
+            }
+            GC.Collect();
+        }
+
+
+        public void MakeLeak(int iRep)
+        {
+            for(int i=0; i<iRep; i++)
+            {
+                Mv_Doub[i] = null;
+            }
+            GC.Collect();
+        }
+
+
+        public void ThreadStart()
+        {
+            for(int i=0; i<15; i++)
+            {
+                SetLink(iRep, iObj);
+                MakeLeak(iRep);
+            }
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlbigleakthd.csproj b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlbigleakthd.csproj
new file mode 100644 (file)
index 0000000..47b6040
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="DLBigLeakThd.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="DoubLink.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlbigleakthd_v2.csproj b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlbigleakthd_v2.csproj
new file mode 100644 (file)
index 0000000..51b606c
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="dLBigLeakThd.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="DoubLink.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlcollect.cs b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlcollect.cs
new file mode 100644 (file)
index 0000000..a3a0c53
--- /dev/null
@@ -0,0 +1,104 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**************************************************************
+/* a test case based on DoubLinkStay. Instead of saving references
+/* into array, it save them into List<object>
+/* to see if GC can handle Collections references correctly.
+/**************************************************************/
+
+namespace DoubLink {
+    using System;
+    using System.Collections.Generic;
+
+    public class DLCollect
+    {
+
+        internal DoubLink []Mv_Doub;
+        internal List<DoubLink> Mv_Collect;
+
+        public static int Main(String [] Args)
+        {
+            int iRep = 0;
+            int iObj = 0;
+
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+            switch( Args.Length )
+            {
+                case 1:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 20;
+                    }
+                break;
+
+                case 2:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 20;
+                    }
+                    if (!Int32.TryParse( Args[1], out iObj ))
+                    {
+                        iObj = 10;
+                    }
+                break;
+
+                default:
+                    iRep = 20;
+                    iObj = 10;
+                break;
+
+            }
+
+            DLCollect Mv_Leak = new DLCollect();
+            if(Mv_Leak.runTest(iRep, iObj ))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+
+            Console.WriteLine("Test Failed");
+            return 1;
+
+        }
+
+
+        public bool runTest(int iRep, int iObj)
+        {
+
+            Mv_Collect = new List<DoubLink>(iRep);
+            for(int i=0; i <10; i++)
+            {
+                SetLink(iRep, iObj);
+                Mv_Collect.RemoveRange(0, Mv_Collect.Count);
+                GC.Collect();
+            }
+
+            GC.WaitForPendingFinalizers();
+
+            Console.WriteLine("{0} DLinkNodes finalized", DLinkNode.FinalCount);
+            return (DLinkNode.FinalCount==iRep*iObj*10);
+        }
+
+
+        public void SetLink(int iRep, int iObj)
+        {
+            Mv_Doub = new DoubLink[iRep];
+
+            for(int i=0; i<iRep; i++)
+            {
+                // create DoubLink element in array
+                Mv_Doub[i] = new DoubLink(iObj);
+
+                // add DoubLink element to List<object>
+                Mv_Collect.Add(Mv_Doub[i]);
+
+                // kill reference to DoubLink in array
+                Mv_Doub[i] = null;
+            }
+
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlcollect.csproj b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlcollect.csproj
new file mode 100644 (file)
index 0000000..268a91b
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="DLCollect.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="DoubLink.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlstack.cs b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlstack.cs
new file mode 100644 (file)
index 0000000..5aea958
--- /dev/null
@@ -0,0 +1,120 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**************************************************************
+/* a test case based on DoubLinkStay. Instead of delete all of
+/* the reference to a Cyclic Double linked list, it creats one
+/* reference to the first node of the linked list and save it in
+/* a local array in SetLink, then delete all old reference. To
+/* check if GC collects leak when the local array out of stack.
+/**************************************************************/
+
+namespace DoubLink {
+
+    using System;
+
+    public class DLStack
+    {
+
+        internal DoubLink[] Mv_Doub;
+        internal int n_count = 0;
+
+        public static int Main(System.String [] Args)
+        {
+            int iRep = 100;
+            int iObj = 10;
+
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+            switch( Args.Length )
+            {
+                case 1:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 100;
+                    }
+                break;
+
+                case 2:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 100;
+                    }
+                    if (!Int32.TryParse( Args[1], out iObj ))
+                    {
+                        iObj = 10;
+                    }
+                break;
+
+                default:
+                    iRep = 100;
+                    iObj = 10;
+                break;
+            }
+
+            DLStack Mv_Leak = new DLStack();
+            if(Mv_Leak.runTest(iRep, iObj ))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            Console.WriteLine("Test Failed");
+            return 1;
+
+        }
+
+
+        public bool runTest(int iRep, int iObj)
+        {
+
+            for(int i=0; i <10; i++)
+            {
+                SetLink(iRep, iObj);
+                MakeLeak(iRep);
+            }
+
+                       long lastTotalMemory = long.MaxValue;
+                       long curTotalMemory = GC.GetTotalMemory(false);
+                       
+                       while (lastTotalMemory != curTotalMemory)
+                       {
+                               GC.Collect();
+                               GC.WaitForPendingFinalizers();
+
+                               lastTotalMemory = curTotalMemory;
+                               curTotalMemory = GC.GetTotalMemory(false);
+                       }
+
+            Console.WriteLine("{0} DLinkNodes finalized", DLinkNode.FinalCount);
+            return (DLinkNode.FinalCount==iRep*iObj*10);
+
+        }
+
+
+        public void SetLink(int iRep, int iObj)
+        {
+            DLinkNode[] Mv_DLink;
+
+            Mv_Doub = new DoubLink[iRep];
+            Mv_DLink = new DLinkNode[iRep*10];
+
+            for(int i=0; i<iRep; i++)
+            {
+                Mv_Doub[i] = new DoubLink(iObj);
+                Mv_DLink[n_count] = Mv_Doub[i][0];
+                n_count++;
+            }
+
+        }
+
+
+        public void MakeLeak(int iRep)
+        {
+            for(int i=0; i<iRep; i++)
+            {
+                Mv_Doub[i] = null;
+            }
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlstack.csproj b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/dlstack.csproj
new file mode 100644 (file)
index 0000000..fd11138
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="DLStack.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="DoubLink.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinkgen.cs b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinkgen.cs
new file mode 100644 (file)
index 0000000..9c5e4b6
--- /dev/null
@@ -0,0 +1,179 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**************************************************************
+/* a basic test case for GC with cyclic Double linked list leaks.
+/* Creat a DoubLink object which is a cyclic Double linked list
+/* object with iObj number node. then deletes its reference when
+/* the next object is created. Do this loop iRep times.
+/**************************************************************/
+
+namespace DoubLink {
+    using System;
+
+    public class DoubLinkGen
+    {
+// disabling unused variable warning
+#pragma warning disable 0414
+        internal DoubLink Mv_Doub;
+#pragma warning restore 0414
+
+        public static int Main(System.String [] Args)
+        {
+            int iRep = 0;
+            int iObj = 0;
+
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+            switch( Args.Length )
+            {
+                case 1:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 100;
+                    }
+                break;
+
+                case 2:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 100;
+                    }
+                    if (!Int32.TryParse( Args[1], out iObj ))
+                    {
+                        iObj = 10;
+                    }
+                break;
+
+                default:
+                    iRep = 100;
+                    iObj = 10;
+                break;
+            }
+
+            DoubLinkGen Mv_Leak = new DoubLinkGen();
+            if(Mv_Leak.runTest(iRep, iObj ))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            Console.WriteLine("Test Failed");
+            return 1;
+        }
+
+
+        public bool runTest(int iRep, int iObj)
+        {
+            SetLink(iRep, iObj);
+            Mv_Doub = null;
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+
+            Console.Write(DLinkNode.FinalCount);
+            Console.WriteLine(" DLinkNodes finalized");
+            return (DLinkNode.FinalCount==iRep*iObj);
+
+        }
+
+
+        public void SetLink(int iRep, int iObj)
+        {
+            for(int i=0; i<iRep; i++)
+            {
+                Mv_Doub = new DoubLink(iObj);
+            }
+
+        }
+
+    }
+
+    public class DoubLink
+    {
+        internal DLinkNode[] Mv_DLink;
+
+        public DoubLink(int Num)
+            : this(Num, false)
+        {
+        }
+
+        public DoubLink(int Num, bool large)
+        {
+
+            Mv_DLink = new DLinkNode[Num];
+
+            if (Num == 0)
+            {
+                return;
+            }
+
+            if (Num == 1)
+            {
+                // only one element
+                Mv_DLink[0] = new DLinkNode((large ? 250 : 1), Mv_DLink[0], Mv_DLink[0]);
+                return;
+            }
+
+            // first element
+            Mv_DLink[0] = new DLinkNode((large ? 250 : 1), Mv_DLink[Num - 1], Mv_DLink[1]);
+
+            // all elements in between
+            for (int i = 1; i < Num - 1; i++)
+            {
+                Mv_DLink[i] = new DLinkNode((large ? 250 : i + 1), Mv_DLink[i - 1], Mv_DLink[i + 1]);
+            }
+
+            // last element
+            Mv_DLink[Num - 1] = new DLinkNode((large ? 250 : Num), Mv_DLink[Num - 2], Mv_DLink[0]);
+        }
+
+
+        public int NodeNum
+        {
+            get
+            {
+                return Mv_DLink.Length;
+            }
+        }
+
+
+        public DLinkNode this[int index]
+        {
+            get
+            {
+                return Mv_DLink[index];
+            }
+
+            set
+            {
+                Mv_DLink[index] = value;
+            }
+        }
+
+    }
+
+    public class DLinkNode
+    {
+        // disabling unused variable warning
+#pragma warning disable 0414
+        internal DLinkNode Last;
+        internal DLinkNode Next;
+        internal int[] Size;
+#pragma warning restore 0414
+
+        public static int FinalCount = 0;
+
+        public DLinkNode(int SizeNum, DLinkNode LastObject, DLinkNode NextObject)
+        {
+            Last = LastObject;
+            Next = NextObject;
+            Size = new int[SizeNum * 1024];
+        }
+
+        ~DLinkNode()
+        {
+            FinalCount++;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinkgen.csproj b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinkgen.csproj
new file mode 100644 (file)
index 0000000..b0ebf65
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="doubLinkGen.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinknoleak.cs b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinknoleak.cs
new file mode 100644 (file)
index 0000000..1910b06
--- /dev/null
@@ -0,0 +1,95 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**************************************************************
+/* this test creates Cyclic double linked list objects in a loop,
+/* before creat a new object, it delete all node references to root
+/* except the first node to make a fake leak for GC.
+/**************************************************************/
+
+namespace DoubLink {
+    using System;
+    using System.Collections.Generic;
+
+    public class DoubLinkNoLeak
+    {
+        internal DoubLink[] Mv_Doub;
+        internal Queue<DLinkNode> Mv_Save = new Queue<DLinkNode>(10);
+
+        public static int Main(System.String [] Args)
+        {
+            int iRep = 0;
+            int iObj = 0;
+
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+            switch( Args.Length )
+            {
+                case 1:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 30;
+                    }
+                break;
+
+                case 2:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 30;
+                    }
+                    if (!Int32.TryParse( Args[1], out iObj ))
+                    {
+                        iObj = 10;
+                    }
+                break;
+
+                default:
+                    iRep = 30;
+                    iObj = 10;
+                break;
+            }
+
+            DoubLinkNoLeak Mv_Leak = new DoubLinkNoLeak();
+            if(Mv_Leak.runTest(iRep, iObj ))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            Console.WriteLine("Test Failed");
+            return 1;
+        }
+
+
+        public bool runTest(int iRep, int iObj)
+        {
+            for(int i=0; i<10; i++)
+            {
+                SetLink(iRep, iObj);
+            }
+
+            Mv_Doub = null;
+            Mv_Save = null;
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+
+            Console.WriteLine("{0} DLinkNodes finalized", DLinkNode.FinalCount);
+            return (DLinkNode.FinalCount==iRep*iObj*10);
+
+        }
+
+
+        public void SetLink(int iRep, int iObj)
+        {
+            Mv_Doub = new DoubLink[iRep];
+            for(int i=0; i<iRep; i++)
+            {
+                Mv_Doub[i] = new DoubLink(iObj);
+                Mv_Save.Enqueue(Mv_Doub[i][0]);
+            }
+
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinknoleak.csproj b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinknoleak.csproj
new file mode 100644 (file)
index 0000000..5742139
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="doubLinkNoLeak.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="DoubLink.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinknoleak2.cs b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinknoleak2.cs
new file mode 100644 (file)
index 0000000..ee41f04
--- /dev/null
@@ -0,0 +1,209 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**************************************************************
+/* a test case based on DoubLinkStay. Instead of delete all of
+/* the reference to a Cyclic Double linked list, it creats one
+/* reference to the first node of the linked list, then delete all old
+/* reference. This test trys to make fake leak for GC.
+/**************************************************************/
+
+namespace DoubLink {
+    using System;
+
+    public class DoubLinkNoLeak2
+    {
+
+        internal DoubLink[] Mv_Doub;
+        internal DLinkNode[] Mv_DLink;
+        internal int n_count = 0;
+
+        public static int Main(System.String [] Args)
+        {
+            int iRep = 0;
+            int iObj = 0;
+
+            switch( Args.Length )
+            {
+                case 1:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 5;
+                    }
+                    iObj = 10;
+                break;
+
+                case 2:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 5;
+                    }
+                    if (!Int32.TryParse( Args[1], out iObj ))
+                    {
+                        iObj = 10;
+                    }
+                break;
+
+                default:
+                    iRep = 5;
+                    iObj = 10;
+                break;
+            }
+
+            DoubLinkNoLeak2 Mv_Leak = new DoubLinkNoLeak2();
+            if(Mv_Leak.runTest(iRep, iObj ))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            Console.WriteLine("Test Failed");
+            return 1;
+
+        }
+
+
+        public bool runTest(int iRep, int iObj)
+        {
+            Mv_DLink = new DLinkNode[iRep*10];
+
+            for(int i=0; i <10; i++)
+            {
+                SetLink(iRep, iObj);
+                MakeLeak(iRep);
+            }
+
+            Mv_DLink = null;
+            Mv_Doub = null;
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            //do a second GC collect since some nodes may have been still alive at the time of first collect
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            int totalNodes = iRep * iObj * 10;
+            Console.Write(DLinkNode.FinalCount);
+            Console.Write(" DLinkNodes finalized out of ");
+            Console.WriteLine(totalNodes);
+
+            return (DLinkNode.FinalCount == totalNodes);
+
+        }
+
+
+        public void SetLink(int iRep, int iObj)
+        {
+            Mv_Doub = new DoubLink[iRep];
+
+            for(int i=0; i<iRep; i++)
+            {
+                Mv_Doub[i] = new DoubLink(iObj);
+
+                Mv_DLink[n_count] = Mv_Doub[i][0];
+                n_count++;
+            }
+
+        }
+
+
+        public void MakeLeak(int iRep)
+        {
+
+            for(int i=0; i<iRep; i++)
+            {
+                Mv_Doub[i] = null;
+            }
+        }
+
+    }
+
+    public class DoubLink
+    {
+        internal DLinkNode[] Mv_DLink;
+
+        public DoubLink(int Num)
+            : this(Num, false)
+        {
+        }
+
+        public DoubLink(int Num, bool large)
+        {
+
+            Mv_DLink = new DLinkNode[Num];
+
+            if (Num == 0)
+            {
+                return;
+            }
+
+            if (Num == 1)
+            {
+                // only one element
+                Mv_DLink[0] = new DLinkNode((large ? 250 : 1), Mv_DLink[0], Mv_DLink[0]);
+                return;
+            }
+
+            // first element
+            Mv_DLink[0] = new DLinkNode((large ? 250 : 1), Mv_DLink[Num - 1], Mv_DLink[1]);
+
+            // all elements in between
+            for (int i = 1; i < Num - 1; i++)
+            {
+                Mv_DLink[i] = new DLinkNode((large ? 250 : i + 1), Mv_DLink[i - 1], Mv_DLink[i + 1]);
+            }
+
+            // last element
+            Mv_DLink[Num - 1] = new DLinkNode((large ? 250 : Num), Mv_DLink[Num - 2], Mv_DLink[0]);
+        }
+
+
+        public int NodeNum
+        {
+            get
+            {
+                return Mv_DLink.Length;
+            }
+        }
+
+
+        public DLinkNode this[int index]
+        {
+            get
+            {
+                return Mv_DLink[index];
+            }
+
+            set
+            {
+                Mv_DLink[index] = value;
+            }
+        }
+
+    }
+
+    public class DLinkNode
+    {
+        // disabling unused variable warning
+#pragma warning disable 0414
+        internal DLinkNode Last;
+        internal DLinkNode Next;
+        internal int[] Size;
+#pragma warning restore 0414
+
+        public static int FinalCount = 0;
+
+        public DLinkNode(int SizeNum, DLinkNode LastObject, DLinkNode NextObject)
+        {
+            Last = LastObject;
+            Next = NextObject;
+            Size = new int[SizeNum * 1024];
+        }
+
+        ~DLinkNode()
+        {
+            FinalCount++;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinknoleak2.csproj b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinknoleak2.csproj
new file mode 100644 (file)
index 0000000..b387806
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="doubLinkNoLeak2.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinkstay.cs b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinkstay.cs
new file mode 100644 (file)
index 0000000..ab0ea49
--- /dev/null
@@ -0,0 +1,194 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/******************************************************************
+/*Test case for testing GC with cyclic double linked list leaks
+/*In every loop. SetLink() to create a doubLink object array whose size
+/*is iRep,  each DoubLink Object is a iObj node cyclic double
+/*linked list. MakeLeak() deletes all the object reference in the array
+/*to make all the cyclic double linked lists become memory leaks.
+/*objects' life time is longer than DoubLinkGen.
+/******************************************************************/
+
+namespace DoubLink {
+    using System;
+
+    public class DoubLinkStay
+    {
+        internal DoubLink[] Mv_Doub;
+
+        public static int Main(System.String [] Args)
+        {
+            int iRep = 100;
+            int iObj = 10;
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            switch( Args.Length )
+            {
+                case 1:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 100;
+                    }
+                break;
+
+                case 2:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 100;
+                    }
+                    if (!Int32.TryParse( Args[1], out iObj ))
+                    {
+                        iObj = 10;
+                    }
+                break;
+
+                default:
+                    iRep = 100;
+                    iObj = 10;
+                break;
+            }
+
+            DoubLinkStay Mv_Leak = new DoubLinkStay();
+            if(Mv_Leak.runTest(iRep, iObj ))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            Console.WriteLine("Test Failed");
+            return 1;
+
+        }
+
+        public bool runTest(int iRep, int iObj)
+        {
+            Mv_Doub = new DoubLink[iRep];
+            for(int i=0; i<20; i++)
+            {
+                SetLink(iRep, iObj);
+                MakeLeak(iRep);
+            }
+
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            Console.Write(DLinkNode.FinalCount);
+            Console.WriteLine(" DLinkNodes finalized");
+            return (DLinkNode.FinalCount==iRep*iObj*20);
+
+        }
+
+        public void SetLink(int iRep, int iObj)
+        {
+
+            for(int i=0; i<iRep; i++)
+            {
+                Mv_Doub[i] = new DoubLink(iObj);
+            }
+
+        }
+
+
+        public void MakeLeak(int iRep)
+        {
+            for(int i=0; i<iRep; i++)
+            {
+                Mv_Doub[i] = null;
+            }
+        }
+
+    }
+
+    public class DoubLink
+    {
+        internal DLinkNode[] Mv_DLink;
+
+        public DoubLink(int Num)
+            : this(Num, false)
+        {
+        }
+
+        public DoubLink(int Num, bool large)
+        {
+
+            Mv_DLink = new DLinkNode[Num];
+
+            if (Num == 0)
+            {
+                return;
+            }
+
+            if (Num == 1)
+            {
+                // only one element
+                Mv_DLink[0] = new DLinkNode((large ? 250 : 1), Mv_DLink[0], Mv_DLink[0]);
+                return;
+            }
+
+            // first element
+            Mv_DLink[0] = new DLinkNode((large ? 250 : 1), Mv_DLink[Num - 1], Mv_DLink[1]);
+
+            // all elements in between
+            for (int i = 1; i < Num - 1; i++)
+            {
+                Mv_DLink[i] = new DLinkNode((large ? 250 : i + 1), Mv_DLink[i - 1], Mv_DLink[i + 1]);
+            }
+
+            // last element
+            Mv_DLink[Num - 1] = new DLinkNode((large ? 250 : Num), Mv_DLink[Num - 2], Mv_DLink[0]);
+        }
+
+
+        public int NodeNum
+        {
+            get
+            {
+                return Mv_DLink.Length;
+            }
+        }
+
+
+        public DLinkNode this[int index]
+        {
+            get
+            {
+                return Mv_DLink[index];
+            }
+
+            set
+            {
+                Mv_DLink[index] = value;
+            }
+        }
+
+    }
+
+    public class DLinkNode
+    {
+        // disabling unused variable warning
+#pragma warning disable 0414
+        internal DLinkNode Last;
+        internal DLinkNode Next;
+        internal int[] Size;
+#pragma warning restore 0414
+
+        public static int FinalCount = 0;
+
+        public DLinkNode(int SizeNum, DLinkNode LastObject, DLinkNode NextObject)
+        {
+            Last = LastObject;
+            Next = NextObject;
+            Size = new int[SizeNum * 1024];
+        }
+
+        ~DLinkNode()
+        {
+            FinalCount++;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinkstay.csproj b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/doublinkstay.csproj
new file mode 100644 (file)
index 0000000..95c3430
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="DoubLinkStay.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/DoublinkList/project.json b/src/coreclr/tests/src/GC/Scenarios/DoublinkList/project.json
deleted file mode 100644 (file)
index 14c11d2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "dependencies": {
-    "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
-    "System.Collections": "4.0.10",
-    "System.Collections.NonGeneric": "4.0.1-beta-23302",
-    "System.Collections.Specialized": "4.0.1-beta-23302",
-    "System.ComponentModel": "4.0.1-beta-23302",
-    "System.Console": "4.0.0-beta-23302",
-    "System.Diagnostics.Process": "4.0.0-beta-23302",
-    "System.Globalization": "4.0.10",
-    "System.Globalization.Calendars": "4.0.0",
-    "System.IO": "4.0.10",
-    "System.IO.FileSystem": "4.0.0",
-    "System.IO.FileSystem.Primitives": "4.0.0",
-    "System.Linq": "4.0.1-beta-23302",
-    "System.Linq.Queryable": "4.0.1-beta-23302",
-    "System.Reflection": "4.0.10",
-    "System.Reflection.Primitives": "4.0.0",
-    "System.Runtime": "4.0.20",
-    "System.Runtime.Extensions": "4.0.10",
-    "System.Runtime.Handles": "4.0.0",
-    "System.Runtime.InteropServices": "4.0.20",
-    "System.Runtime.Loader": "4.0.0-beta-23302",
-    "System.Text.Encoding": "4.0.10",
-    "System.Threading": "4.0.10",
-    "System.Xml.ReaderWriter": "4.0.11-beta-23302",
-    "System.Xml.XDocument": "4.0.11-beta-23302",
-    "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
-  },
-  "frameworks": {
-    "dnxcore50": {}
-  }
-}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Dynamo/app.config b/src/coreclr/tests/src/GC/Scenarios/Dynamo/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/Dynamo/basenode.cs b/src/coreclr/tests/src/GC/Scenarios/Dynamo/basenode.cs
new file mode 100644 (file)
index 0000000..268d63b
--- /dev/null
@@ -0,0 +1,30 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace Dynamo {
+    using System;
+
+    public class BaseNode
+    {
+        protected int iValue = 0;
+        protected int iType = 111111;
+        public static Dynamo Cv_Dynamo;
+
+        public int Value {
+            get { return iValue; }
+            set { iValue = value; }
+        }
+
+        public int Type {
+            get { return iType; }
+        }
+
+        ~BaseNode()
+        {
+            if (Cv_Dynamo!=null)
+                Cv_Dynamo.RegisterCleanup( Type, Value );
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Dynamo/dynamo.cs b/src/coreclr/tests/src/GC/Scenarios/Dynamo/dynamo.cs
new file mode 100644 (file)
index 0000000..d4a6559
--- /dev/null
@@ -0,0 +1,303 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*
+ * Changes:
+ *   -removed hardcoded Dyanmo parameters
+ *   -allow Dynamo parameters to be passed from command-line
+ *   -checks 3 random nodes, as well as first & last nodes
+ *   -added ability to pass random seed
+ *   -outputs random seed for reproducibility
+ *   -fixed crashes, caught exceptions
+ *   -improved analysis logic
+ *   -converted getters/setters to properties
+ *   -removed unused/useless methods
+ *   -general code cleanup
+ *
+ * As far as I can tell, this code creates one StaticNode that links to 2 DynamoNodes
+ * which in turn links to an array of RandomNodes for each DynamoNode.  It then kills
+ * 5 StaticNodes by  setting them to null.  It then checks to see if the StaticNodes'
+ * finalizers have been run, thus cleaning up the linked nodes.
+ *
+ * There are quite a few arrays and ints that don't seem to be used for anything,
+ * as labeled below.
+ * Notes:
+ *   -passes with complus_gcstress=0,1,2,3,4
+ *   -passes with complus_hitminops
+ *   -passes in debug
+ */
+
+
+namespace Dynamo {
+    using System;
+    using System.Threading;
+    using System.Diagnostics;
+
+    public class Dynamo
+    {
+        protected StaticNode [] NodeBank;
+        protected int [] LessRandomValues;
+        protected int [] LargeRandomValues;
+        protected int [] DynamoValues = new int[2]; // what is this for?
+        protected int StaticValue;                  // what is this for?
+
+        protected int [] ChkRandomValues;
+        protected int ChkRandomNum = 0;
+        protected int [] ChkDynamoValues;           // what is this for?
+        protected int ChkDynamoNum = 0;             // what is this for?
+        protected int ChkStaticValue;               // what is this for?
+
+        public static int Main( String [] args)
+        {
+            int seed = (int)DateTime.Now.Ticks;
+            if ( args.Length==3 )
+            {
+                if (!Int32.TryParse(args[2], out seed))
+                {
+                    // incorrect value passed to Dynamo
+                    Usage();
+                    return 1;
+                }
+            }
+            else if ( args.Length!=2 ) {
+                // incorrect number of parameters
+                Usage();
+                return 1;
+            }
+
+            Dynamo Mv_Dynamo;
+            int numElements, numDynamics;
+
+            if (!Int32.TryParse(args[0], out numElements) || !Int32.TryParse(args[1], out numDynamics))
+            {
+                Usage();
+                return 1;
+            }
+
+            try
+            {
+                Mv_Dynamo = new Dynamo( numElements, numDynamics );
+            } catch ( ArgumentException e) {
+                // incorrect value passed to Dynamo
+                Console.WriteLine("Dynamo: " + e.Message);
+                return 1;
+            }
+
+            if ( Mv_Dynamo.RunTest(seed ))
+                return 100; //pass
+
+            return 1;   //fail
+        }
+
+
+        // prints usage message to console
+        public static void Usage() {
+            Console.WriteLine("Usage: Dynamo n m [seed]");
+            Console.WriteLine("       where n is the number of elements");
+            Console.WriteLine("       and m is the number of dynamo nodes");
+            Console.WriteLine("       ( m<=n; m,n>10 )");
+            Console.WriteLine("       seed is an optional random seed, by default DateTime.Now.Ticks is used");
+        }
+
+        // begins the test
+        public bool RunTest(int randomSeed )
+        {
+            Console.WriteLine( "Total amount of RandomNode Memory: "  );
+            Console.WriteLine( RandomNode.TotalMemory );
+            Console.WriteLine( " " );
+            Console.WriteLine( "Running Finalize Test..." );
+            Console.WriteLine( " ");
+
+            Prep( );
+            bool result = false;
+
+            // kill the first and last nodes
+            if (KillNode(0) && KillNode(NodeBank.Length-1) ) {
+
+                // kill three random nodes
+                result = true;
+                int[] randNums = {0, 0, 0};
+                for (int i=0; i<2; i++) {
+                    // choose a random index to kill
+                    Random rand = new Random(randomSeed);
+                    do {
+                        randNums[i] = rand.Next() % NodeBank.Length;
+                        // make sure we don't kill a previously killed node!
+                    } while ( (randNums[i]==0)
+                               || (randNums[i]==NodeBank.Length-1)
+                               || (randNums[i]==randNums[(i+1)%3])
+                               || (randNums[i]==randNums[(i+2)%3]) );
+
+                    if (!KillNode(randNums[i])) {
+                        result = false;
+                        break;
+                    }
+                }
+            }
+
+            Console.WriteLine();
+            if ( result )
+                Console.WriteLine("Test Passed with seed: " + randomSeed);
+            else
+                Console.WriteLine("Test Failed with seed: " + randomSeed);
+
+            return result;
+        }
+
+
+        public void Prep( )
+        {
+            StaticNode.Cv_Dynamo = this; // No worries - static fields are not references - they are roots
+            ChkRandomValues = new int[ NodeBank[0].SmallNode.Length + NodeBank[0].LargeNode.Length ];
+        }
+
+
+        public void AnalyzeNode( int StaticNode )
+        {
+            LessRandomValues = new int[ NodeBank[ StaticNode ].SmallNode.Length];
+            LargeRandomValues = new int [ NodeBank[ StaticNode ].LargeNode.Length ];
+
+            DynamoValues[ 0 ] = NodeBank[ StaticNode ].SmallNode.Value;
+            DynamoValues[ 1 ] = NodeBank[ StaticNode ].LargeNode.Value;
+
+            Debug.Assert(NodeBank[ StaticNode ].SmallNode.Length == NodeBank[ StaticNode ].LargeNode.Length);
+
+            for( int i = 0; i < NodeBank[ StaticNode ].SmallNode.Length; i++ )  {
+                LessRandomValues[ i ] = NodeBank[ StaticNode ].SmallNode[i].Value;
+                LargeRandomValues[ i ] = NodeBank[ StaticNode ].LargeNode[i].Value;
+            }
+
+            StaticValue = NodeBank[ StaticNode ].Value;
+        }
+
+
+        public bool Compare( )
+        {
+            Thread.CurrentThread.Join(10);
+
+            // First check to see if the right number of Random Nodes are destroyed
+            int ChkRan = ( LessRandomValues.Length + LargeRandomValues.Length );
+
+            if( ChkRandomNum != ChkRan)
+            {
+                Console.WriteLine( "The registered number: " + ChkRan  );
+                Console.WriteLine( "The analyzed number: " + ChkRandomNum  );
+                Console.WriteLine( "The registered number and analyzed number are not equal" );
+                return false;
+            }
+
+            // Note: This does not find a node if it was cleaned up by mistake.
+            for( int i = 0; i < ChkRan; i++ )
+            {
+                int CheckValue = ChkRandomValues[ i ];
+                bool foundLess = false, foundLarge = false;
+
+                foreach (int j in LessRandomValues)
+                {
+                    if( CheckValue == j )  {
+                        foundLess = true;
+                        break;
+                    }
+                }
+
+                if ( !foundLess )
+                {
+                    foreach (int j in LargeRandomValues)
+                    {
+                        if( CheckValue == j )  {
+                            foundLarge = true;
+                            break;
+                        }
+                    }
+
+                    if ( !foundLarge )
+                    {
+                        Console.WriteLine( "Match not found! Random Node: ");
+                        Console.WriteLine( CheckValue );
+                        Console.WriteLine(" did not get cleaned up.");
+                        return false;
+                    }
+
+                }
+
+            }
+
+            return true;
+        }
+
+
+        public void RegisterCleanup( int Type, int Value )
+        {
+            switch( Type )
+            {
+                case 0:
+                    // static node
+                    ChkStaticValue = Value;
+                break;
+                case 1:
+                    // dynamo node
+                    ChkDynamoValues[ ChkDynamoNum++ ] = Value;
+                break;
+                case 2:
+                    // random node
+                    if (ChkRandomNum<ChkRandomValues.Length)
+                        ChkRandomValues[ ChkRandomNum++ ] = Value;
+                    break;
+                default:
+                    Console.WriteLine( "Test error has occured: Unknown Type - {0} given", Type );
+                break;
+            }
+        }
+
+
+        public bool KillNode( int Node)
+        {
+            Console.WriteLine("Deleting Node:");
+            Console.WriteLine( Node );
+
+            AnalyzeNode( Node );        // <- Finalizers not supported
+            NodeBank[ Node ] = null;    // <- Finalizers not supported
+
+            GC.Collect(); // Could attempt to cause GC instead of attempting to force it
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+
+            bool Result = Compare( ); // finalizers not supported
+
+            ChkDynamoNum = 0; // finalizers not supported
+            ChkRandomNum = 0; // finalizers not supported
+
+            return Result;
+        }
+
+
+        public Dynamo( int numElements, int numDynamics )
+        {
+
+            Console.WriteLine(" ");
+
+            if ( (numElements < numDynamics ) || (numDynamics<10))
+                throw new ArgumentException();
+            else
+            {
+                ChkDynamoValues = new int[numDynamics];
+                NodeBank = new StaticNode[numDynamics/2];
+                int iDynamic = numElements / numDynamics;
+
+                int Low = 0;
+                int High = iDynamic * 2;
+
+                for( int i = 0; i < NodeBank.Length; i++ )
+                {
+                    NodeBank[i] = new StaticNode( Low, High );
+
+                    Low = High;
+                    High += iDynamic * 2;
+                }
+            }
+
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Dynamo/dynamo.csproj b/src/coreclr/tests/src/GC/Scenarios/Dynamo/dynamo.csproj
new file mode 100644 (file)
index 0000000..c697d81
--- /dev/null
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>1000 40 191919</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="Dynamo.cs" />
+    <Compile Include="BaseNode.cs" />
+    <Compile Include="DynamoNode.cs" />
+    <Compile Include="RandomNode.cs" />
+    <Compile Include="StaticNode.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/Dynamo/dynamonode.cs b/src/coreclr/tests/src/GC/Scenarios/Dynamo/dynamonode.cs
new file mode 100644 (file)
index 0000000..81d4f61
--- /dev/null
@@ -0,0 +1,48 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace Dynamo {
+    using System;
+
+    public class DynamoNode : BaseNode
+    {
+
+        protected RandomNode [] DynamicArray;
+
+        public DynamoNode( int LowNum, int HighNum, int Value)
+        {
+
+            if (HighNum<LowNum)
+                throw new FormatException("HighNum must be <= LowNum");
+
+            iType = 1;
+            this.Value = Value;
+
+            DynamicArray = new RandomNode[ HighNum - LowNum ];
+
+            for( int iCounter = 0, i = LowNum; i < HighNum; i++,  iCounter++)
+                DynamicArray[ iCounter ] = new RandomNode( i * ( HighNum - LowNum ), i );
+
+        }
+
+        public int Length
+        {
+            get { return DynamicArray.Length; }
+        }
+
+        public RandomNode this[int index]
+        {
+            get {
+                try {
+                    return DynamicArray[ index ];
+                }
+                catch (IndexOutOfRangeException) {
+                    return null;
+                }
+            }
+        }
+
+    }
+}
+
diff --git a/src/coreclr/tests/src/GC/Scenarios/Dynamo/randomnode.cs b/src/coreclr/tests/src/GC/Scenarios/Dynamo/randomnode.cs
new file mode 100644 (file)
index 0000000..9b42d1f
--- /dev/null
@@ -0,0 +1,35 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace Dynamo {
+    using System;
+
+    public class RandomNode : BaseNode
+    {
+        public static int TotalMemory = 0;
+
+        protected byte [] SimpleSize;
+        protected int size = 0;
+
+
+        public RandomNode( int Size, int Value )
+        {
+            this.Value = Value;
+            iType = 2;
+
+            if ( Size < 0 )
+                throw new FormatException("Size must >= 0");
+            else if ( Size > 0 ) {
+                SimpleSize = new byte[ Size ];
+                SimpleSize[0] = (byte)255;
+                SimpleSize[Size - 1] = (byte)255;
+
+                TotalMemory+=Size;
+                size = Size;
+            }
+
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Dynamo/staticnode.cs b/src/coreclr/tests/src/GC/Scenarios/Dynamo/staticnode.cs
new file mode 100644 (file)
index 0000000..2daa543
--- /dev/null
@@ -0,0 +1,41 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace Dynamo {
+    using System;
+
+    public class StaticNode : BaseNode
+    {
+        protected static int siValue = 200065;
+
+        protected DynamoNode smallNode;
+        protected DynamoNode largeNode;
+
+        public StaticNode( int LowNum, int HighNum )
+        {
+
+            if (HighNum<LowNum)
+                throw new FormatException("HighNum must be <= LowNum");
+
+            Value = siValue++;
+            iType = 0;
+
+            int Half = (HighNum - LowNum) / 2;
+
+            SmallNode = new DynamoNode( LowNum, (LowNum + Half), (siValue + 100000) );
+            LargeNode = new DynamoNode( ( LowNum + Half ), HighNum, (siValue + 100001) );
+        }
+
+        public DynamoNode SmallNode {
+            get { return smallNode; }
+            set { smallNode = value; }
+        }
+
+        public DynamoNode LargeNode {
+            get { return largeNode; }
+            set { largeNode = value; }
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/FinalNStruct/finalnstruct.cs b/src/coreclr/tests/src/GC/Scenarios/FinalNStruct/finalnstruct.cs
new file mode 100644 (file)
index 0000000..dec9926
--- /dev/null
@@ -0,0 +1,68 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+//***************************************************************************/
+//* Test:   FinalNStruct
+//* Coverage:   1. check if GC can collect NStruct memeory (externally_allocated
+//*     memory correctly.
+//*     2. If all NStruct's finalize() get called after they lose ref.
+//****************************************************************************/
+
+namespace NStruct {
+    using System;
+
+    internal class FinalNStruct
+    {
+
+        public static STRMAP[] CreateObj(int iObj)
+        {
+
+            STRMAP []strmap = new STRMAP[iObj];
+            for (int i=0; i< iObj; i++ ) //allocate 3100KB
+            {
+                strmap[i] = new STRMAP();
+            }
+            return strmap;
+
+        }
+
+        public static bool RunTest(int iObj,STRMAP []strmap)
+        {
+
+            for( int i=0; i< iObj; i++ )
+            {
+                strmap[i] = null;
+            }
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+
+            return ( FinalizeCount.icFinal == FinalizeCount.icCreat );
+
+        }
+
+        public static int Main(String [] args){
+
+            int iObj = 100;
+            STRMAP []strmaptemp;
+
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            strmaptemp = CreateObj(iObj);
+            if (RunTest(iObj,strmaptemp))
+            {
+                Console.WriteLine( "Created objects number is same with finalized objects." );
+                Console.WriteLine( "Test Passed !" );
+                return 100;
+            }
+
+            Console.WriteLine( "Created objects number is not same with finalized objects (" + FinalizeCount.icFinal + " of " + FinalizeCount.icCreat + ")");
+            Console.WriteLine( "Test failed !" );
+            return 1;
+
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/FinalNStruct/finalnstruct.csproj b/src/coreclr/tests/src/GC/Scenarios/FinalNStruct/finalnstruct.csproj
new file mode 100644 (file)
index 0000000..5ea0a22
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="FinalNStruct.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="strmap.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/FinalNStruct/nstructresur.cs b/src/coreclr/tests/src/GC/Scenarios/FinalNStruct/nstructresur.cs
new file mode 100644 (file)
index 0000000..0de2dbc
--- /dev/null
@@ -0,0 +1,63 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*****************************************************************************/
+/* Test:    NStructResur
+/* Coverage:    NStruct objects' finalize can be called and the objects can be
+/*      resurrected in finalize correctly. (verify it by accessing the
+/*      objects after finalization.
+/******************************************************************************/
+
+namespace NStruct {
+    using System;
+    using System.Collections.Generic;
+
+    internal class NStructResur
+    {
+        internal static List<STRMAP> alstrmap;
+
+        public static void CreateObj(int iObj)
+        {
+            alstrmap = new List<STRMAP>();
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            for( int i=0; i< iObj; i++ ) //allocat 3100KB
+            {
+                alstrmap.Add(new STRMAP() );
+            }
+
+            alstrmap = new List<STRMAP>();
+
+        }
+
+        public static bool RunTest()
+        {
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+
+            for(int i=0; i<alstrmap.Count; i++)
+            {
+                alstrmap[i].AccessElement();
+            }
+
+            Console.WriteLine("Created object: {0}, Finalized objects: {1}", FinalizeCount.icCreat, FinalizeCount.icFinal);
+            return ( FinalizeCount.icFinal == FinalizeCount.icCreat );
+        }
+
+        public static int Main(String [] args)
+        {
+            CreateObj(100);
+            if (RunTest())
+            {
+                Console.WriteLine( "Test Passed" );
+                return 100;
+            }
+            Console.WriteLine( "Test failed" );
+            return 1;
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/FinalNStruct/nstructresur.csproj b/src/coreclr/tests/src/GC/Scenarios/FinalNStruct/nstructresur.csproj
new file mode 100644 (file)
index 0000000..74479be
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="NStructResur.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="strmap.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/FinalNStruct/nstructtun.cs b/src/coreclr/tests/src/GC/Scenarios/FinalNStruct/nstructtun.cs
new file mode 100644 (file)
index 0000000..2523fcc
--- /dev/null
@@ -0,0 +1,74 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace NStruct {
+    using System;
+
+    internal class NStructTun
+    {
+
+        public class CreateObj
+        {
+// disabling unused variable warning
+#pragma warning disable 0414
+            private STRMAP Strmap;
+#pragma warning restore 0414
+            public CreateObj(int Rep)
+            {
+                 for( int i=0; i< Rep; i++ )
+                 {
+                    Strmap = new STRMAP();
+                 }
+             }
+
+            public bool RunTest()
+            {
+                Strmap=null;
+
+                GC.Collect();
+                GC.WaitForPendingFinalizers();
+                GC.Collect();
+
+                Console.Out.WriteLine(FinalizeCount.icCreat + " NStruct Objects were deleted and "+ FinalizeCount.icFinal +" finalized.");
+
+                return (FinalizeCount.icCreat == FinalizeCount.icFinal );
+            }
+
+        }
+
+        public static int Main(String [] Args)
+        {
+            int iRep = 0;
+
+            Console.Out.WriteLine("Test should return with ExitCode 100 ...");
+
+            if( Args.Length == 1)
+            {
+                if (!Int32.TryParse( Args[0], out iRep ))
+                {
+                    iRep =10000;
+                }
+            }
+            else
+            {
+                iRep =10000;
+            }
+            Console.Out.WriteLine("iRep = "+iRep );
+
+            CreateObj temp = new CreateObj(iRep);
+
+            if(temp.RunTest())
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+
+            Console.WriteLine("Test Failed");
+            return 1;
+
+        }
+    }
+
+
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/FinalNStruct/nstructtun.csproj b/src/coreclr/tests/src/GC/Scenarios/FinalNStruct/nstructtun.csproj
new file mode 100644 (file)
index 0000000..b272f18
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="NStructTun.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <ProjectReference Include="strmap.csproj" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/FinalNStruct/project.json b/src/coreclr/tests/src/GC/Scenarios/FinalNStruct/project.json
deleted file mode 100644 (file)
index 14c11d2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "dependencies": {
-    "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
-    "System.Collections": "4.0.10",
-    "System.Collections.NonGeneric": "4.0.1-beta-23302",
-    "System.Collections.Specialized": "4.0.1-beta-23302",
-    "System.ComponentModel": "4.0.1-beta-23302",
-    "System.Console": "4.0.0-beta-23302",
-    "System.Diagnostics.Process": "4.0.0-beta-23302",
-    "System.Globalization": "4.0.10",
-    "System.Globalization.Calendars": "4.0.0",
-    "System.IO": "4.0.10",
-    "System.IO.FileSystem": "4.0.0",
-    "System.IO.FileSystem.Primitives": "4.0.0",
-    "System.Linq": "4.0.1-beta-23302",
-    "System.Linq.Queryable": "4.0.1-beta-23302",
-    "System.Reflection": "4.0.10",
-    "System.Reflection.Primitives": "4.0.0",
-    "System.Runtime": "4.0.20",
-    "System.Runtime.Extensions": "4.0.10",
-    "System.Runtime.Handles": "4.0.0",
-    "System.Runtime.InteropServices": "4.0.20",
-    "System.Runtime.Loader": "4.0.0-beta-23302",
-    "System.Text.Encoding": "4.0.10",
-    "System.Threading": "4.0.10",
-    "System.Xml.ReaderWriter": "4.0.11-beta-23302",
-    "System.Xml.XDocument": "4.0.11-beta-23302",
-    "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
-  },
-  "frameworks": {
-    "dnxcore50": {}
-  }
-}
index cd37dce..9bf6bdf 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
   </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
   </ItemGroup>
index e7ef60d..5fa8b55 100644 (file)
     <Compile Include="FinalizeTimeout.cs" />
   </ItemGroup>
   <ItemGroup>
-    <None Include="project.json" />
+    <None Include="$(GCPackagesConfigFileDirectory)minimal\project.json" />
   </ItemGroup>
-  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)minimal\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)minimal\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
 </Project>
diff --git a/src/coreclr/tests/src/GC/Scenarios/FinalizeTimeout/project.json b/src/coreclr/tests/src/GC/Scenarios/FinalizeTimeout/project.json
deleted file mode 100644 (file)
index 14c11d2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-  "dependencies": {
-    "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
-    "System.Collections": "4.0.10",
-    "System.Collections.NonGeneric": "4.0.1-beta-23302",
-    "System.Collections.Specialized": "4.0.1-beta-23302",
-    "System.ComponentModel": "4.0.1-beta-23302",
-    "System.Console": "4.0.0-beta-23302",
-    "System.Diagnostics.Process": "4.0.0-beta-23302",
-    "System.Globalization": "4.0.10",
-    "System.Globalization.Calendars": "4.0.0",
-    "System.IO": "4.0.10",
-    "System.IO.FileSystem": "4.0.0",
-    "System.IO.FileSystem.Primitives": "4.0.0",
-    "System.Linq": "4.0.1-beta-23302",
-    "System.Linq.Queryable": "4.0.1-beta-23302",
-    "System.Reflection": "4.0.10",
-    "System.Reflection.Primitives": "4.0.0",
-    "System.Runtime": "4.0.20",
-    "System.Runtime.Extensions": "4.0.10",
-    "System.Runtime.Handles": "4.0.0",
-    "System.Runtime.InteropServices": "4.0.20",
-    "System.Runtime.Loader": "4.0.0-beta-23302",
-    "System.Text.Encoding": "4.0.10",
-    "System.Threading": "4.0.10",
-    "System.Xml.ReaderWriter": "4.0.11-beta-23302",
-    "System.Xml.XDocument": "4.0.11-beta-23302",
-    "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
-  },
-  "frameworks": {
-    "dnxcore50": {}
-  }
-}
diff --git a/src/coreclr/tests/src/GC/Scenarios/FragMan/app.config b/src/coreclr/tests/src/GC/Scenarios/FragMan/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/FragMan/fragman.cs b/src/coreclr/tests/src/GC/Scenarios/FragMan/fragman.cs
new file mode 100644 (file)
index 0000000..dcd330c
--- /dev/null
@@ -0,0 +1,311 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/* FragMan
+ *
+ * This test creates an array of FragNodes, then reorganizes them into a tree.
+ * Then it removes the references from the array, and verifies the tree keeps
+ * all the elements alive (verified by checking the Finalized count against 0).
+*/
+
+namespace DefaultNamespace {
+    using System;
+
+    public class FragMan
+    {
+
+        internal int nodeCount = 0;
+        internal FragNode fnM = null;
+        internal FragNode [] CvA_FNodes;
+
+        public static int Main ( String [] Args)
+        {
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+            FragMan test = new FragMan( );
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            if (FragNode.Finalized == 0)
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+
+            Console.Write(FragNode.Finalized);
+            Console.WriteLine(" FragNodes were prematurely finalized");
+            Console.WriteLine("Test Failed");
+
+            GC.KeepAlive(test);
+            return 1;
+
+        }
+
+
+        public FragMan( )
+        {
+            buildTree( );
+            fnM = CvA_FNodes[12];
+            CvA_FNodes = null;
+            enumNode( fnM );
+        }
+
+
+        public void enumNode( FragNode Node )
+        {
+
+            nodeCount++;
+
+            Console.WriteLine(Node.Name);
+            if ( Node.Lesser != null )
+            {
+                Console.Write("Lesser is:");
+                Console.WriteLine(Node.Lesser.Name);
+            }
+            if ( Node.Larger != null )
+            {
+                Console.Write("Larger is:");
+                Console.WriteLine(Node.Larger.Name);
+            }
+
+            Console.WriteLine();
+
+            if ( Node.Lesser != null )
+            {
+                enumNode( Node.Lesser );
+            }
+            if ( Node.Larger != null )
+            {
+                enumNode( Node.Larger );
+            }
+
+        }
+
+
+        public void buildTree( )
+        {
+            CvA_FNodes = new FragNode[26];
+            for (int i=0; i<CvA_FNodes.Length; i++)
+            {
+                CvA_FNodes[i] = new FragNode((char)((int)'A'+i));
+
+            }
+
+            //  0
+            CvA_FNodes[ 0 ].Parent =( CvA_FNodes[  1 ] );          // B
+
+            //  1
+            CvA_FNodes[ 1 ].Parent =( CvA_FNodes[  3 ] );          // D
+            CvA_FNodes[ 1 ].Lesser =( CvA_FNodes[  0 ] );          // A
+            CvA_FNodes[ 1 ].Larger =( CvA_FNodes[  2 ] );          // C
+
+
+            // 2
+            CvA_FNodes[ 2 ].Parent =( CvA_FNodes[  1 ] );          // B
+
+
+            // 3
+            CvA_FNodes[ 3 ].Parent =( CvA_FNodes[  6 ] );          // G
+            CvA_FNodes[ 3 ].Lesser =( CvA_FNodes[  1 ] );          // B
+            CvA_FNodes[ 3 ].Larger =( CvA_FNodes[  5 ] );          // F
+
+
+            // 4
+            CvA_FNodes[ 4 ].Parent =( CvA_FNodes[  5 ] );          // F
+
+
+            // 5
+            CvA_FNodes[ 5 ].Parent =( CvA_FNodes[  3 ] );          // D
+            CvA_FNodes[ 5 ].Lesser =( CvA_FNodes[  4 ] );          // E
+
+
+            // 6
+            CvA_FNodes[ 6 ].Parent =( CvA_FNodes[  12 ] );         // M
+            CvA_FNodes[ 6 ].Lesser =( CvA_FNodes[  3 ] );          // D
+            CvA_FNodes[ 6 ].Larger =( CvA_FNodes[  9 ] );          // J
+
+
+            // 7
+            CvA_FNodes[ 7 ].Parent =( CvA_FNodes[  9 ] );          // J
+            CvA_FNodes[ 7 ].Larger =( CvA_FNodes[  8 ] );          // I
+
+
+            // 8
+            CvA_FNodes[ 8 ].Parent =( CvA_FNodes[  7 ] );          // H
+
+
+            // 9
+            CvA_FNodes[ 9 ].Parent =( CvA_FNodes[  6 ] );          // G
+            CvA_FNodes[ 9 ].Lesser =( CvA_FNodes[  7 ] );          // H
+            CvA_FNodes[ 9 ].Larger =( CvA_FNodes[  11 ] );         // L
+
+
+            // 10
+            CvA_FNodes[ 10 ].Parent =( CvA_FNodes[  11 ] );        // L
+
+
+            // 11
+            CvA_FNodes[ 11 ].Parent =( CvA_FNodes[  9 ] );         // J
+            CvA_FNodes[ 11 ].Lesser =( CvA_FNodes[  10 ] );        // K
+
+
+            // 12
+            CvA_FNodes[ 12 ].Root= true;
+            CvA_FNodes[ 12 ].Lesser =( CvA_FNodes[  6 ] );         // G
+            CvA_FNodes[ 12 ].Larger =( CvA_FNodes[  19 ] );        // T
+
+
+            // 13
+            CvA_FNodes[ 13 ].Parent =( CvA_FNodes[  14 ] );        // O
+
+
+            // 14
+            CvA_FNodes[ 14 ].Parent =( CvA_FNodes[  16 ] );        // Q
+            CvA_FNodes[ 14 ].Lesser =( CvA_FNodes[  13 ] );        // N
+            CvA_FNodes[ 14 ].Larger =( CvA_FNodes[  15 ] );        // P
+
+
+            // 15
+            CvA_FNodes[ 15 ].Parent =( CvA_FNodes[ 14 ] );         // O
+
+
+            // 16
+            CvA_FNodes[ 16 ].Parent =( CvA_FNodes[ 19 ] );         // T
+            CvA_FNodes[ 16 ].Lesser =( CvA_FNodes[ 14 ] );         // O
+            CvA_FNodes[ 16 ].Larger =( CvA_FNodes[ 18 ] );         // S
+
+
+            // 17
+            CvA_FNodes[ 17 ].Parent =( CvA_FNodes[ 18 ] );         // S
+
+
+            // 18
+            CvA_FNodes[ 18 ].Parent =( CvA_FNodes[ 16 ] );         // Q
+            CvA_FNodes[ 18 ].Lesser =( CvA_FNodes[ 17 ] );         // R
+
+
+            // 19
+            CvA_FNodes[ 19 ].Parent =( CvA_FNodes[ 12 ] );         // M
+            CvA_FNodes[ 19 ].Lesser =( CvA_FNodes[ 16 ] );         // Q
+            CvA_FNodes[ 19 ].Larger =( CvA_FNodes[ 22 ] );         // W
+
+
+            // 20
+            CvA_FNodes[ 20 ].Parent =( CvA_FNodes[ 22 ] );         // W
+            CvA_FNodes[ 20 ].Larger =( CvA_FNodes[  21 ] );        // V
+
+
+            // 21
+            CvA_FNodes[ 21 ].Parent =( CvA_FNodes[  20 ] );        // U
+
+
+            // 22
+            CvA_FNodes[ 22 ].Parent =( CvA_FNodes[  19 ] );        // T
+            CvA_FNodes[ 22 ].Lesser =( CvA_FNodes[  20 ] );        // U
+            CvA_FNodes[ 22 ].Larger =( CvA_FNodes[  24 ] );        // Y
+
+
+            // 23
+            CvA_FNodes[ 23 ].Parent =( CvA_FNodes[ 24 ] );         // Y
+
+
+            // 24
+            CvA_FNodes[ 24 ].Parent =( CvA_FNodes[  22 ] );        // W
+            CvA_FNodes[ 24 ].Lesser =( CvA_FNodes[  23 ] );        // X
+            CvA_FNodes[ 24 ].Larger =( CvA_FNodes[  25 ] );        // Z
+
+
+            // 25
+            CvA_FNodes[ 25 ].Parent =( CvA_FNodes[ 24 ] );         // Y
+
+        }
+
+    }
+
+    public class FragNode
+    {
+        internal bool Cv_bRoot = false;
+        internal FragNode Cv_FNodeUpper = null, Cv_FNodeLess = null, Cv_FNodeGreat = null;
+        internal char Cv_SName;
+        public static int Finalized = 0;
+
+        public FragNode(char name)
+        {
+            Cv_SName = name;
+        }
+
+        ~FragNode()
+        {
+            Console.WriteLine("{0} finalized!", Cv_SName);
+            Finalized++;
+        }
+
+        public bool Root
+        {
+            get
+            {
+                return Cv_bRoot;
+            }
+
+            set
+            {
+                Cv_bRoot = value;
+            }
+        }
+
+        public char Name
+        {
+            get
+            {
+                return Cv_SName;
+            }
+
+        }
+
+
+        public FragNode Parent
+        {
+            get
+            {
+                return Cv_FNodeUpper;
+            }
+
+            set
+            {
+                Cv_FNodeUpper = value;
+            }
+        }
+
+
+        public FragNode Lesser
+        {
+            get
+            {
+                return Cv_FNodeLess;
+            }
+
+            set
+            {
+                Cv_FNodeLess = value;
+            }
+        }
+
+
+
+        public FragNode Larger
+        {
+            get
+            {
+                return Cv_FNodeGreat;
+            }
+
+            set
+            {
+                Cv_FNodeGreat = value;
+            }
+        }
+
+    }
+
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/FragMan/fragman.csproj b/src/coreclr/tests/src/GC/Scenarios/FragMan/fragman.csproj
new file mode 100644 (file)
index 0000000..6ecec0f
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="FragMan.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/GCBase1/app.config b/src/coreclr/tests/src/GC/Scenarios/GCBase1/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/GCBase1/gc_base1.cs b/src/coreclr/tests/src/GC/Scenarios/GCBase1/gc_base1.cs
new file mode 100644 (file)
index 0000000..733081f
--- /dev/null
@@ -0,0 +1,171 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace DefaultNamespace {
+    using System;
+
+    public class GC_Base1
+    {
+        internal RandomNode[] CvA_RandomNode;
+
+        public static int Main( System.String [] Args )
+        {
+
+            int iRep = 0;
+            int iObj = 0;
+
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            switch( Args.Length )
+            {
+               case 1:
+                   if (!Int32.TryParse( Args[0], out iRep ))
+                   {
+                       iRep = 15;
+                   }
+               break;
+               case 2:
+                   if (!Int32.TryParse( Args[0], out iRep ))
+                   {
+                       iRep = 15;
+                   }
+                   if (!Int32.TryParse( Args[1], out iObj ))
+                   {
+                       iObj = 1000;
+                   }
+               break;
+               default:
+                   iRep = 15;
+                   iObj = 1000;
+               break;
+            }
+
+            GC_Base1 Mv_Base = new GC_Base1();
+
+            if(Mv_Base.runTest(iRep, iObj ))
+            {
+                Console.WriteLine( "Test Passed" );
+                return 100;
+            }
+            else
+            {
+                Console.WriteLine( "Test Failed" );
+                return 1;
+            }
+        }
+
+
+        public bool runTest( int Rep, int Obj )
+        {
+
+            for( int i = 0; i < Rep; i++ )
+            {
+                CvA_RandomNode = new RandomNode[ Obj ];
+
+                for( int j = 0; j < Obj; j++ )
+                {
+                    CvA_RandomNode[ j ] = new RandomNode( j, j );
+                    if( j == 0 )
+                    {
+                        CvA_RandomNode[ j ].setBigSize( 0 );
+                    }
+                }
+
+                CvA_RandomNode = null;
+
+                GC.Collect();
+            }
+
+            return true;
+
+        }
+
+    }
+
+    public class BaseNode
+    {
+        internal int iValue = 0;
+        internal int iType = 111111;
+
+        internal static bool UseFinals = true;
+
+        public static bool getUseFinal()
+        {
+            return UseFinals;
+        }
+
+        public static void setUseFinal(bool Final)
+        {
+            UseFinals = Final;
+        }
+
+        public virtual void setValue(int Value)
+        {
+            iValue = Value;
+        }
+
+        public virtual int getValue()
+        {
+            return iValue;
+        }
+
+        public virtual void setType(int Type)
+        {
+            iType = Type;
+        }
+
+        public virtual int getType()
+        {
+            return iType;
+        }
+
+    }
+
+    public class RandomNode : BaseNode
+    {
+        internal byte[] SimpleSize;
+        internal static int iSize = 0;
+        internal int iiSize = 0;
+
+        public RandomNode(int Size, int value)
+        {
+            setValue(value);
+            setType(2);
+            SimpleSize = new byte[Size];
+
+            if (Size != 0)
+            {
+                SimpleSize[0] = (byte)255;
+                SimpleSize[Size - 1] = (byte)255;
+            }
+
+            setSize(Size);
+
+        }
+
+        public virtual void setSize(int Size)
+        {
+            iiSize = Size;
+            iSize += Size;
+        }
+
+        public virtual int getSize()
+        {
+            return iiSize;
+        }
+
+        public virtual int getBigSize()
+        {
+            return iSize;
+        }
+
+        public virtual void setBigSize(int Size)
+        {
+            iSize = Size;
+        }
+
+
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/GCBase1/gc_base1.csproj b/src/coreclr/tests/src/GC/Scenarios/GCBase1/gc_base1.csproj
new file mode 100644 (file)
index 0000000..f122060
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>3 100</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="GC_Base1.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/GCBase1/gc_base1_1.csproj b/src/coreclr/tests/src/GC/Scenarios/GCBase1/gc_base1_1.csproj
new file mode 100644 (file)
index 0000000..4d8f3bc
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>8 100</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="GC_Base1.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/GCBench/app.config b/src/coreclr/tests/src/GC/Scenarios/GCBench/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/GCBench/gcbench.cs b/src/coreclr/tests/src/GC/Scenarios/GCBench/gcbench.cs
new file mode 100644 (file)
index 0000000..11ffcb4
--- /dev/null
@@ -0,0 +1,171 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+// This is adapted from a benchmark written by John Ellis and Pete Kovac
+// of Post Communications.
+// It was modified by Hans Boehm of Silicon Graphics.
+//
+//      This is no substitute for real applications.  No actual application
+//      is likely to behave in exactly this way.  However, this benchmark was
+//      designed to be more representative of real applications than other
+//      GC benchmarks of which we are aware.
+//      It attempts to model those properties of allocation requests that
+//      are important to current GC techniques.
+//      It is designed to be used either to obtain a single overall performance
+//      number, or to give a more detailed estimate of how collector
+//      performance varies with object lifetimes.  It prints the time
+//      required to allocate and collect balanced binary trees of various
+//      sizes.  Smaller trees result in shorter object lifetimes.  Each cycle
+//      allocates roughly the same amount of memory.
+//      Two data structures are kept around during the entire process, so
+//      that the measured performance is representative of applications
+//      that maintain some live in-memory data.  One of these is a tree
+//      containing many pointers.  The other is a large array containing
+//      double precision floating point numbers.  Both should be of comparable
+//      size.
+//
+//      The results are only really meaningful together with a specification
+//      of how much memory was used.  It is possible to trade memory for
+//      better time performance.  This benchmark should be run in a 32 MB
+//      heap, though we don't currently know how to enforce that uniformly.
+//
+//      Unlike the original Ellis and Kovac benchmark, we do not attempt
+//      measure pause times.  This facility should eventually be added back
+//      in.  There are several reasons for omitting it for now.  The original
+//      implementation depended on assumptions about the thread scheduler
+//      that don't hold uniformly.  The results really measure both the
+//      scheduler and GC.  Pause time measurements tend to not fit well with
+//      current benchmark suites.  As far as we know, none of the current
+//      commercial  implementations seriously attempt to minimize GC pause
+//      times.
+
+namespace DefaultNamespace {
+    using System;
+
+    internal class Node
+    {
+        internal Node left;
+        internal Node right;
+
+        internal Node(Node l, Node r)
+        {
+            left = l;
+            right = r;
+        }
+
+        internal Node()
+        {
+        }
+    }
+
+    public class GCBench
+    {
+
+        public const int kStretchTreeDepth    = 18;      // about 16Mb
+        public const int kLongLivedTreeDepth  = 16;  // about 4Mb
+        public const int kArraySize  = 50;  // about 4Mb
+        public const int kMinTreeDepth = 4;
+        public const int kMaxTreeDepth = 16;
+
+        // Nodes used by a tree of a given size
+        internal static int TreeSize(int i)
+        {
+            return ((1 << (i + 1)) - 1);
+        }
+
+        // Number of iterations to use for a given tree depth
+        internal static int NumIters(int i)
+        {
+            return 2 * TreeSize(kStretchTreeDepth) / TreeSize(i);
+        }
+
+        // Build tree top down, assigning to older objects.
+        internal static void Populate(int iDepth, Node thisNode)
+        {
+            if (iDepth<=0)
+            {
+                return;
+            }
+            else
+            {
+                iDepth--;
+                thisNode.left  = new Node();
+                thisNode.right = new Node();
+                Populate (iDepth, thisNode.left);
+                Populate (iDepth, thisNode.right);
+            }
+        }
+
+        // Build tree bottom-up
+        internal static Node MakeTree(int iDepth)
+        {
+            if (iDepth<=0)
+            {
+                return new Node();
+            }
+            else
+            {
+                return new Node(MakeTree(iDepth-1), MakeTree(iDepth-1));
+            }
+        }
+
+        internal void TimeConstruction(int depth)
+        {
+
+            int     iNumIters = NumIters(depth);
+            Node    tempTree;
+
+            for (int i = 0; i < iNumIters; ++i)
+            {
+                tempTree = new Node();
+                Populate(depth, tempTree);
+                tempTree = null;
+            }
+
+
+            for (int i = 0; i < iNumIters; ++i)
+            {
+                tempTree = MakeTree(depth);
+                tempTree = null;
+            }
+
+        }
+
+        public static int Main(String [] args)
+        {
+            Node    longLivedTree;
+            Node    tempTree;
+
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            GCBench Mv_Obj = new GCBench();
+
+            // Stretch the memory space quickly
+            tempTree = MakeTree(kStretchTreeDepth);
+            tempTree = null;
+
+            // Create a long lived object
+            longLivedTree = new Node();
+            Populate(kLongLivedTreeDepth, longLivedTree);
+
+            // Create long-lived array, filling half of it
+            double []array = new double[kArraySize];
+            for (int i = 0; i < kArraySize/2; ++i)
+            {
+                array[i] = 1.0/i;
+            }
+
+            GC.Collect();
+
+            for (int d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2)
+            {
+                Mv_Obj.TimeConstruction(d);
+            }
+
+            Console.WriteLine("Test Passed");
+            return 100;
+        }
+    }
+
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/GCBench/gcbench.csproj b/src/coreclr/tests/src/GC/Scenarios/GCBench/gcbench.csproj
new file mode 100644 (file)
index 0000000..4644445
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="GCBench.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/GCStress/app.config b/src/coreclr/tests/src/GC/Scenarios/GCStress/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/GCStress/gcstress.cs b/src/coreclr/tests/src/GC/Scenarios/GCStress/gcstress.cs
new file mode 100644 (file)
index 0000000..4862d1b
--- /dev/null
@@ -0,0 +1,75 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace DefaultNamespace {
+    using System;
+
+    internal class GCStress
+    {
+        internal GCStress next;
+        internal byte[] data;
+
+        public static int Main(String [] args)
+        {
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+            GCStress obj= new GCStress();
+            if (obj.RunTest())
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+
+            Console.WriteLine("Test Failed");
+            return 1;
+        }
+
+
+        public bool RunTest()
+        {
+            GCStress garbage;
+            GCStress head = null;
+            GCStress tail = null;
+            GCStress walker;
+            int stressCount = 0;
+            int stressCount2 = 0;
+
+            for (int i=0; i<1500000; i++)
+            {
+                byte[] x = new byte [(i %1111)];
+
+                if ((i%100) == 0)
+                {
+                    garbage = new GCStress();
+                    garbage.data = x;
+                    stressCount += x.Length;
+                    if (head == null)
+                    {
+                        head = garbage;
+                    }
+                    else
+                    {
+                        tail.next = garbage;
+                    }
+
+                    tail = garbage;
+                }
+            }
+
+
+            walker = head;
+            while (walker != null)
+            {
+                if (walker.data != null)
+                {
+                    stressCount2 += walker.data.Length;
+                }
+                walker = walker.next;
+            }
+
+            Console.WriteLine ("Stress count: {0} {1}", stressCount, stressCount2);
+            return (stressCount == stressCount2);
+        }
+    }
+
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/GCStress/gcstress.csproj b/src/coreclr/tests/src/GC/Scenarios/GCStress/gcstress.csproj
new file mode 100644 (file)
index 0000000..6c9caa3
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="gcstress.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/LeakGen/app.config b/src/coreclr/tests/src/GC/Scenarios/LeakGen/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/LeakGen/leakgen.cs b/src/coreclr/tests/src/GC/Scenarios/LeakGen/leakgen.cs
new file mode 100644 (file)
index 0000000..9235256
--- /dev/null
@@ -0,0 +1,110 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+
+namespace LGen {
+    using System;
+
+    public class LeakGen
+    {
+        public static int Main(System.String [] Args)
+        {
+            int iRep = 0;
+            int iObj = 0; //the number of Mb will be allocated in MakeLeak();
+           
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            switch( Args.Length )
+            {
+                case 1:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 2;
+                    }
+                break;
+                case 2:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 2;
+                    }
+                    if (!Int32.TryParse( Args[1], out iObj ))
+                    {
+                        iObj = 10;
+                    }
+                break;
+                default:
+                    iRep = 2;
+                    iObj = 10;
+                break;
+            }
+
+            LeakGen Mv_Leak = new LeakGen();
+            if(Mv_Leak.runTest(iRep, iObj ))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            else
+            {
+                Console.WriteLine("Test Failed");
+                return 1;
+            }
+        }
+
+
+        public bool runTest(int iRep, int iObj)
+        {
+
+            for(int i = 0; i<iRep; i++)
+            {
+                /*allocate about 10MB memory include MakeLeak() */
+                MakeLeak(iObj);
+            }
+
+            Console.WriteLine("~LeakObject() was called {0} times.", LeakObject.icFinal);
+            return (LeakObject.icFinal == iObj*iRep);
+        }
+
+
+        public void MakeLeak(int iObj)
+        {
+            int [] mem;
+
+            LeakObject []Mv_Obj = new LeakObject[iObj];
+            for(int i=0; i<iObj; i++)
+            {
+                Mv_Obj[i] = new LeakObject(i);
+                mem = new int[1024*250]; //nearly 1MB memory, larger than this will get assert failure .
+                mem[0] = 1;
+                mem[mem.Length-1] = 1;
+            }
+
+            Mv_Obj = null;
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+
+        }
+
+
+    }
+
+    public class LeakObject
+    {
+        internal int[] mem;
+        public static int icFinal = 0;
+        public LeakObject(int num)
+        {
+            mem = new int[1024 * 250]; //nearly 1MB memory, larger than this will get assert failure.
+            mem[0] = num;
+            mem[mem.Length - 1] = num;
+        }
+
+        ~LeakObject()
+        {
+            LeakObject.icFinal++;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/LeakGen/leakgen.csproj b/src/coreclr/tests/src/GC/Scenarios/LeakGen/leakgen.csproj
new file mode 100644 (file)
index 0000000..b7c433a
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="LeakGen.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/LeakGen/leakgenthrd.cs b/src/coreclr/tests/src/GC/Scenarios/LeakGen/leakgenthrd.cs
new file mode 100644 (file)
index 0000000..96704f6
--- /dev/null
@@ -0,0 +1,131 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+
+namespace LGen {
+    using System.Threading;
+    using System;
+    using System.IO;
+
+    public class LeakGenThrd
+    {
+        internal int myObj;
+        internal int Cv_iCounter = 0;
+        internal int Cv_iRep;
+
+        public static int Main(System.String [] Args)
+        {
+            int iRep = 2;
+            int iObj = 15; //the number of MB memory will be allocted in MakeLeak()
+
+            // synchronized console output Console.SetOut(TextWriter.Synchronized(Console.Out));
+            Console.Out.WriteLine("Test should return with ExitCode 100 ...");
+
+            switch( Args.Length )
+            {
+                case 1:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 2;
+                    }
+                break;
+                case 2:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 2;
+                    }
+                    if (!Int32.TryParse( Args[1], out iObj ))
+                    {
+                        iObj = 15;
+                    }
+                break;
+                default:
+                    iRep = 2;
+                    iObj = 15;
+                break;
+            }
+
+            LeakGenThrd Mv_Leak = new LeakGenThrd();
+            if(Mv_Leak.runTest(iRep, iObj ))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            else
+            {
+                Console.WriteLine("Test Failed");
+                return 1;
+            }
+        }
+
+
+        public bool runTest(int iRep, int iObj)
+        {
+            Cv_iRep = iRep;
+            myObj = iObj;
+
+            Thread Mv_Thread = new Thread(new ThreadStart(this.ThreadStart));
+            Mv_Thread.Start( );
+
+            for(int i = 0; i<iRep; i++)
+            {
+                MakeLeak(iObj);
+            }
+
+            return true;
+        }
+
+
+
+        public void ThreadStart( )
+        {
+
+            if( Cv_iCounter < Cv_iRep )
+            {
+                LeakObject []Mv_Obj = new LeakObject[myObj];
+                for(int i=0; i<myObj; i++)
+                {
+                    Mv_Obj[i] = new LeakObject(i);
+                }
+
+                Cv_iCounter += 1;
+
+                Thread Mv_Thread = new Thread( new ThreadStart(this.ThreadStart) );
+                Mv_Thread.Start( );
+
+            }
+
+        }
+
+        public void MakeLeak(int iObj)
+        {
+
+            LeakObject []Mv_Obj = new LeakObject[iObj];
+            for(int i=0; i<iObj; i++)
+            {
+                Mv_Obj[i] = new LeakObject(i);
+            }
+
+        }
+
+    }
+
+    public class LeakObject
+    {
+        internal int[] mem;
+        public static int icFinal = 0;
+        public LeakObject(int num)
+        {
+            mem = new int[1024 * 250]; //nearly 1MB memory, larger than this will get assert failure.
+            mem[0] = num;
+            mem[mem.Length - 1] = num;
+        }
+
+        ~LeakObject()
+        {
+            LeakObject.icFinal++;
+        }
+    }
+
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/LeakGen/leakgenthrd.csproj b/src/coreclr/tests/src/GC/Scenarios/LeakGen/leakgenthrd.csproj
new file mode 100644 (file)
index 0000000..642a696
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="LeakGenThrd.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/LeakWheel/app.config b/src/coreclr/tests/src/GC/Scenarios/LeakWheel/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/LeakWheel/leakwheel.cs b/src/coreclr/tests/src/GC/Scenarios/LeakWheel/leakwheel.cs
new file mode 100644 (file)
index 0000000..f67c260
--- /dev/null
@@ -0,0 +1,542 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+//************************************************************************/
+//*Test:    LeakWheel
+//*Purpose: simulate real world objects allocating and deleting condation.
+//*Description: It create an object table with "iTable" items. Random number
+//* generator will generate number between 0 to iTable, that is ID in the
+//* Table. object will be added or deleted from that table item.
+//* Oject may be varied size, may create a new thread doing the same thing
+//* like main thread. may be a link list. Delete Object may delete single
+//* object, delete a list of object or delete all objects. While create
+//* object, if the table item has had one object, put this object as it's
+//* child object to make a link list. This tests covered link list, Variant
+//* array, Binary tree, finalize, multi_thread, collections, WeakReference.
+//*Arguments:   Arg1:iMem(MB), Arg2: iIter(Number of iterations), Arg3:iTable, Arg4: iSeed
+//************************************************************************/
+namespace DefaultNamespace {
+    using System.Threading;
+    using System;
+    using System.IO;
+    using System.Collections;
+    using System.Collections.Generic;
+
+    internal class LeakWheel
+    {
+        internal static int iSeed;
+        internal static int iIter;
+        internal static int iTable;
+        internal static int iMem;
+        internal Node LstNode;
+
+        public static int Main( String [] Args)
+        {
+            // console synchronization Console.SetOut(TextWriter.Synchronized(Console.Out));
+
+            /*max memory will be used. If heap size is bigger than this, */
+
+            // delete all the objects. Default 10MB
+            iMem = 10;
+
+            //How many iterations
+            iIter = 1500000;
+
+            //Max items number in the object table
+            iTable = 500;
+
+            //Seed for generate random iKey
+            iSeed = (int)DateTime.Now.Ticks; 
+
+            switch( Args.Length )
+            {
+                case 1:
+                    try{
+                        iMem = Int32.Parse( Args[0] );
+                    }
+                    catch(FormatException)
+                    {
+                        Console.WriteLine("FormatException is caught");
+                    }
+                break;
+                case 2:
+                    try{
+                        iMem = Int32.Parse( Args[0] );
+                        iIter = Int32.Parse( Args[1] );
+                    }
+                    catch(FormatException )
+                    {
+                        Console.WriteLine("FormatException is caught");
+                    }
+                break;
+                case 3:
+                    try{
+                        iMem = Int32.Parse( Args[0] );
+                        iIter = Int32.Parse( Args[1] );
+                        iTable = Int32.Parse( Args[2] );
+                    }
+                    catch(FormatException )
+                    {
+                        Console.WriteLine("FormatException is caught");
+                    }
+                 break;
+                case 4:
+                    try
+                    {
+                        iMem = Int32.Parse(Args[0]);
+                        iIter = Int32.Parse(Args[1]);
+                        iTable = Int32.Parse(Args[2]);
+                        iSeed = Int32.Parse(Args[3]);
+                    }
+                    catch (FormatException)
+                    {
+                        Console.WriteLine("FormatException is caught");
+                    }
+                break;
+            }
+
+            Console.WriteLine("Repro with these values:");
+            Console.WriteLine("iMem= {0} MB, iIter= {1}, iTable={2} iSeed={3}", iMem, iIter, iTable, iSeed );
+
+            LeakWheel mv_obj = new LeakWheel();
+            
+
+            if(mv_obj.RunGame())
+            {
+                Console.WriteLine("Test Passed!");
+                return 100;
+            }
+
+            Console.WriteLine("Test Failed!");
+            return 1;
+
+        }
+
+        public bool RunGame()
+        {
+            Dictionary<int, WeakReference> oTable = new Dictionary<int, WeakReference>(10);
+            LstNode = null; //the last node in the node chain//
+            Random  r = new Random (LeakWheel.iSeed);
+
+            for(int i=0; i<iIter; i++)
+            {
+                LstNode = SpinWheel(oTable, LstNode, r);
+               
+                if( GC.GetTotalMemory(false)/(1024*1024) >= iMem )
+                {
+                    LstNode = null;
+
+                    GC.Collect( );
+                    GC.WaitForPendingFinalizers();
+                    GC.Collect( );
+
+                    Console.WriteLine( "After Delete and GCed all Objects: {0}", GC.GetTotalMemory(false) );
+                }
+            }
+
+            LstNode = null;
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+
+            Thread.Sleep(100);
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+
+
+            Console.WriteLine("When test finished: {0}", GC.GetTotalMemory(false));
+            Console.WriteLine("Created VarAry objects: {0} Finalized VarAry Objects: {1}", Node.iVarAryCreat, Node.iVarAryFinal);
+            Console.WriteLine("Created BitArray objects: {0} Finalized BitArray Objects: {1}", Node.iBitAryCreat, Node.iBitAryFinal);
+            Console.WriteLine("Created small objects: {0} Finalized small Objects: {1}", Node.iSmallCreat, Node.iSmallFinal);
+            Console.WriteLine("Created BinaryTree objects: {0} Finalized BinaryTree Objects: {1}", Node.iBiTreeCreat, Node.iBiTreeFinal);
+            Console.WriteLine("Created Thread objects: {0} Finalized Thread Objects: {1}", Node.iThrdCreat, Node.iThrdFinal);
+
+
+            return (Node.iBitAryCreat == Node.iBitAryFinal &&
+                    Node.iBiTreeCreat == Node.iBiTreeFinal &&
+                    Node.iSmallCreat == Node.iSmallFinal &&
+                    Node.iThrdCreat == Node.iThrdFinal &&
+                    Node.iVarAryCreat == Node.iVarAryFinal);
+        }
+
+        public Node SpinWheel( Dictionary<int, WeakReference> oTable,  Node LstNode, Random r )
+        {
+            int iKey;//the index which the new node will be set at
+            Node nValue;//the new node
+            bool bDel;
+
+            //Console.WriteLine( "start spinwheel ");
+
+            iKey = r.Next( 0, LeakWheel.iTable );
+
+            if( iKey%2 == 0 ) //decide whether delete or create a node.
+                bDel = true; //delete
+            else
+                bDel = false;
+
+            if( !bDel )
+            {
+                nValue = CreateNode( iKey );
+
+                if( oTable.ContainsKey(iKey) && (oTable[iKey]).IsAlive )
+                {
+                    SetChildNode(oTable, iKey, nValue );
+                }
+                else
+                {
+                    LstNode = SetNodeInTable(iKey, nValue, LstNode, oTable);
+                }
+            }
+            else
+            {
+                DeleteNode( iKey, oTable);
+            }
+            //if (iKey % 100 == 0)
+            //{
+            //    Console.WriteLine("HeapSize: {0}", GC.GetTotalMemory(false));
+            //}
+            return LstNode;
+        }
+
+        public void DeleteNode( int iKey, Dictionary<int, WeakReference> oTable)
+        {
+            //iSwitch is 0, delete one child Node at iKey;
+            //is 1, del one object and its childred;
+            //is 2, del the object at iKey and all the next objects;
+            //is 3, del the all objects in object chain.
+            int iSwitch = iKey%4;
+            Node thisNode;
+
+            if( oTable.ContainsKey( iKey ) )
+            {
+                WeakReference wRef = oTable[iKey];
+                if( wRef.IsAlive )
+                {
+                    thisNode = (Node)wRef.Target;
+                    switch( iSwitch )
+                    {
+                        case 0:
+                            Node childNode = thisNode;
+                            if( childNode.Child != null )
+                            {//delete one child Node at iKey if there is,
+                                while( childNode.Child != null )
+                                {
+                                    childNode = childNode.Child;
+                                }
+                                childNode = childNode.Parent;
+                                childNode.Child = null;
+                                break;
+                            }
+                            else goto case 1; //otherwise del this Node in "case 1" (the node is shared with "case 1" );
+                        case 1: //del one object and its childred from nodes chain;
+                            if( thisNode.Last != null )
+                            {
+                                thisNode.Last.Next = thisNode.Next;
+                                if( thisNode.Next != null )
+                                {
+                                    thisNode.Next.Last = thisNode.Last;
+                                }
+                            }
+                            else
+                            {
+                                if( thisNode.Next != null )
+                                    thisNode.Next.Last = null;
+                            }
+                        break;
+                        case 2: //del the object at iKey and all the next objects;
+                            if( thisNode.Last != null )
+                                thisNode.Last = null;
+                            else
+                                thisNode = null;
+                        break;
+                        case 3://del the all objects in object chain.
+                            Node Last = thisNode;
+                            while( Last.Last != null )
+                            {
+                                Last = Last.Last;
+                            }
+                            Last = null;
+                        break;
+                    }//end of switch
+                }
+                else
+                    oTable[iKey] = null;
+            }
+        }
+
+        public Node SetNodeInTable(int iKey, Node nValue, Node LstNode, Dictionary<int, WeakReference> oTable )
+        {
+            /**************************************************/
+            /* save new node in a chain, all the node is      */
+            /* refereced by this chain, Table only have their */
+            /* Weakreferece. So when delete a node, only need */
+            /* to delete the ref in this chain.               */
+            /**************************************************/
+            if( LstNode == null )
+                LstNode = nValue;
+            else
+            {
+                LstNode.Next = nValue ;
+                LstNode.Next.Last = LstNode;
+                LstNode = LstNode.Next;
+            }
+            WeakReference wRef = new WeakReference( LstNode, false );
+            if( oTable.ContainsKey(iKey) )
+            {
+                oTable[iKey] = wRef;
+            }
+            else
+            {
+                oTable.Add( iKey, wRef );
+            }
+            return LstNode; //keep the last node fresh in chain
+        }
+
+        public void SetChildNode( Dictionary<int, WeakReference> oTable, int iKey, Node nValue )
+        {
+            WeakReference wRef= oTable[iKey];
+            WeakReference wRefChild = wRef;
+            Node thisNode = (Node)wRefChild.Target;
+            Node ChildNode = thisNode;
+
+            while( ChildNode.Child != null )
+            {
+                ChildNode = ChildNode.Child;
+            }
+            ChildNode.Child = nValue;
+            ChildNode.Child.Parent = ChildNode;
+        }
+
+        public Node CreateNode( int iKey )
+        {
+            Node newNode = new Node( );
+            switch( iKey%5 )
+            {
+            //case 0://1 out of 4 nodes are thread node.
+            //    newNode.SetThread( );
+            //break;
+            case 1://This node include a binary tree
+                newNode.SettreeNode( iKey );
+            break;
+            case 2: //This node with a Variant array.
+                newNode.SetVararyNode( iKey );
+            break;
+            case 3: //This node with a BitArray
+                newNode.SetBitArrayNode( iKey );
+            break;
+            case 0:
+            case 4: //small node
+                newNode.SetSmallNode( iKey );
+            break;
+            }
+            return newNode;
+        }
+
+        public void ThreadNode()
+        {
+            Dictionary<int, WeakReference> oTable = new Dictionary<int, WeakReference>( 10);
+            Node LstNode = null; //the last node in the node chain//
+            Random  r = new Random (LeakWheel.iSeed);
+            LeakWheel mv_obj = new LeakWheel();
+
+            while (true)
+            {
+                LstNode = mv_obj.SpinWheel( oTable, LstNode, r );
+
+                if( GC.GetTotalMemory(false) >= LeakWheel.iMem*60 )
+                {
+                    LstNode = null;
+
+                    GC.Collect( );
+                    GC.WaitForPendingFinalizers();
+                    GC.Collect( );
+                    Console.WriteLine( "After Delete and GCed all Objects: {0}", GC.GetTotalMemory(false) );
+                }
+            }
+        }
+    }
+
+
+    internal class Node
+    {
+        internal static int iVarAryCreat=0;
+        internal static int iVarAryFinal=0;
+        internal static int iBitAryCreat=0;
+        internal static int iBitAryFinal=0;
+        internal static int iSmallCreat=0;
+        internal static int iSmallFinal=0;
+        internal static int iBiTreeCreat=0;
+        internal static int iBiTreeFinal=0;
+        internal static int iThrdCreat=0;
+        internal static int iThrdFinal=0;
+
+        internal Node Last;
+        internal Node Next;
+        internal Node Parent;
+        internal Node Child;
+// disabling unused variable warning
+#pragma warning disable 0414
+        internal Object vsMem;
+#pragma warning restore 0414
+        internal Thread ThrdNode;
+        internal int itype; //0=VarAry;1=BitAry;2=small;3=binarytree;4=Thread
+
+        public Node()
+        {
+            Last = null;
+            Next = null;
+            Parent = null;
+            Child = null;
+            ThrdNode = null;
+            itype = -1;
+        }
+
+        public void SetVararyNode( int iKey )
+        {
+            int iSize = iKey%30;
+            if (iSize == 0)
+            {
+                iSize = 30;
+            }
+            Object [] VarAry = new Object[iSize];
+            double [] dmem;
+            for( int i=0; i < iSize; i++ )
+            {
+                dmem= new double[1+i];
+                dmem[0] = (double)0;
+                dmem[i] = (double)i;
+                VarAry[i] = ( dmem );
+            }
+
+            vsMem = ( VarAry );
+            itype = 0;
+            AddObjectToRecord();
+        }
+
+        public void SetBitArrayNode( int iKey )
+        {
+            vsMem = ( new BitArray( iKey, true ) );
+            itype = 1;
+            AddObjectToRecord();
+        }
+
+        public void SetSmallNode( int iKey )
+        {
+            itype = 2;
+            AddObjectToRecord();
+            vsMem = ( iKey );
+        }
+
+        public void SettreeNode( int iKey )
+        {
+            itype = 3;
+            AddObjectToRecord();
+            TreeNode nTree = new TreeNode();
+            nTree.Populate(iKey%10, nTree);
+            vsMem = ( nTree );
+        }
+
+        public void SetThread()
+        {
+            itype = 4;
+            AddObjectToRecord();
+            LeakWheel mv_obj = new LeakWheel();
+            mv_obj.ThreadNode();
+        }
+
+
+
+        ~Node()
+        {
+            //that whould be interesting to see what happens if we don't stop the thread
+            //this thread is created in this node, this node go away, this the object chain
+            //is local variable in ThreadNode, it will go away too. What this thread is going to do?
+
+            //if( ThrdNode != null )
+            //{
+            //    ThrdNode.Abort();
+            //    ThrdNode.Join();
+            //}
+            DelObjectFromRecord( );
+        }
+
+        public void AddObjectToRecord()
+        {
+            lock(this) {
+                switch( itype )
+                {
+                case 0:
+                    Node.iVarAryCreat++;
+                    break;
+                case 1:
+                    Node.iBitAryCreat++;
+                    break;
+                case 2:
+                    Node.iSmallCreat++;
+                    break;
+                case 3:
+                    Node.iBiTreeCreat++;
+                    break;
+                case 4:
+                    Node.iThrdCreat++;
+                    break;
+                }
+            }
+        }
+
+        public void DelObjectFromRecord( )
+        {
+            lock(this)
+            {
+                switch( itype )
+                {
+                case 0:
+                    Node.iVarAryFinal++;
+                    break;
+                case 1:
+                    Node.iBitAryFinal++;
+                    break;
+                case 2:
+                    Node.iSmallFinal++;
+                    break;
+                case 3:
+                    Node.iBiTreeFinal++;
+                    break;
+                case 4:
+                    Node.iThrdFinal++;
+                    break;
+                }
+            }
+        }
+    }
+
+    internal class TreeNode
+    {
+        internal TreeNode left;
+        internal TreeNode right;
+        internal byte [] mem;
+        public TreeNode() { }
+
+        // Build tree top down, assigning to older objects.
+        internal void Populate(int iDepth, TreeNode thisNode)
+        {
+            if (iDepth<=0)
+            {
+                return;
+            }
+            else
+            {
+              mem = new byte[iDepth];
+              mem[0] = 0;
+              mem[iDepth-1] = (byte)iDepth;
+              iDepth--;
+              thisNode.left  = new TreeNode();
+              thisNode.right = new TreeNode();
+              Populate (iDepth, thisNode.left);
+              Populate (iDepth, thisNode.right);
+            }
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/LeakWheel/leakwheel.csproj b/src/coreclr/tests/src/GC/Scenarios/LeakWheel/leakwheel.csproj
new file mode 100644 (file)
index 0000000..42b21c2
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="LeakWheel.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/MinLeakGen/app.config b/src/coreclr/tests/src/GC/Scenarios/MinLeakGen/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/MinLeakGen/minleakgen.cs b/src/coreclr/tests/src/GC/Scenarios/MinLeakGen/minleakgen.cs
new file mode 100644 (file)
index 0000000..d6b7e4c
--- /dev/null
@@ -0,0 +1,100 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/***************************************************************************
+/*ByteObject is a class to allocate small size of memory. this test creates
+/*two Large size of ByteObject arrays, then delete all the reference in the
+/* arrays to make millions(iObj) of small leaks to see if GC can handle so
+/*many leaks at same time. ByteObject's size is variable.
+/****************************************************************************/
+namespace DefaultNamespace {
+    using System;
+
+    public class MinLeakGen
+    {
+        internal static ByteObject []Mv_Obj = new ByteObject[1024*5];
+        internal static ByteObject []Mv_Obj1 = new ByteObject[1024*5];
+        public static int Main(System.String [] Args)
+        {
+            int iRep = 0;
+            int iObj = 0; //the number of Mb will be allocated in MakeLeak();
+
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+            switch( Args.Length )
+            {
+                case 1:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 5;
+                    }
+                break;
+
+                case 2:
+                    if (!Int32.TryParse( Args[0], out iRep ))
+                    {
+                        iRep = 5;
+                    }
+                    if (!Int32.TryParse( Args[1], out iObj ))
+                    {
+                        iObj = 1024*5;
+                    }
+                break;
+
+                default:
+                    iRep = 5;
+                    iObj = 1024*5;
+                break;
+
+            }
+
+            MinLeakGen Mv_Leak = new MinLeakGen();
+            if(Mv_Leak.runTest(iRep, iObj ))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            else
+            {
+                Console.WriteLine("Test Failed");
+                return 1;
+            }
+        }
+
+
+        public bool runTest(int iRep, int iObj)
+        {
+            for(int i = 0; i<iRep; i++)
+            {
+                MakeLeak(iObj);
+            }
+            return true;
+        }
+
+        public void MakeLeak(int iObj)
+        {
+            for(int i=0; i<iObj; i++)
+            {
+                Mv_Obj[i] = new ByteObject(i/10+1);
+                Mv_Obj1[i] = new ByteObject(i/10+1);
+            }
+            for(int i=0; i<iObj; i++)
+            {
+                Mv_Obj[i] = null;
+                Mv_Obj1[i] = null;
+            }
+        }
+
+    }
+
+    public class ByteObject
+    {
+        internal byte[] min;
+        public ByteObject(int size)
+        {
+            min = new byte[size];
+            min[0] = 1;
+            min[size - 1] = 2;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/MinLeakGen/minleakgen.csproj b/src/coreclr/tests/src/GC/Scenarios/MinLeakGen/minleakgen.csproj
new file mode 100644 (file)
index 0000000..abf3dbd
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="MinLeakGen.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/NDPin/app.config b/src/coreclr/tests/src/GC/Scenarios/NDPin/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/NDPin/ndpin.cs b/src/coreclr/tests/src/GC/Scenarios/NDPin/ndpin.cs
new file mode 100644 (file)
index 0000000..43089ad
--- /dev/null
@@ -0,0 +1,53 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace DefaultNamespace {
+    using System;
+    using System.Runtime.InteropServices;
+
+    internal class NDPin
+    {
+
+        internal Object p;
+        internal static NDPin m_n;
+        internal static Object m_o;
+
+        internal NDPin (Object p)
+        {
+            this.p = p;
+        }
+
+        public static int Main(String [] args)
+        {
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            m_o = new int[10];
+            GCHandle h = GCHandle.Alloc(m_o, GCHandleType.Pinned);
+
+            for (int i = 0; i < 100000; i++)
+            {
+
+                m_o = new int[10];
+                m_n = new NDPin (m_o);
+                h.Free();
+                h = GCHandle.Alloc(m_o, GCHandleType.Pinned);
+            }
+
+            GC.Collect();
+
+            bool result = (m_o == m_n.p);
+            h.Free();
+
+            if (result)
+            {
+                Console.WriteLine ("Test Passed");
+                return 100;
+            }
+            Console.WriteLine ("Test Failed");
+            return 1;
+        }
+
+    }
+
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/NDPin/ndpin.csproj b/src/coreclr/tests/src/GC/Scenarios/NDPin/ndpin.csproj
new file mode 100644 (file)
index 0000000..d39984c
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="NDPin.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/NDPin/ndpinfinal.cs b/src/coreclr/tests/src/GC/Scenarios/NDPin/ndpinfinal.cs
new file mode 100644 (file)
index 0000000..1cb5e0e
--- /dev/null
@@ -0,0 +1,125 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/******************************************************************/
+/*Test:     NDPinFinal
+/*Purpose:  check if GC works fine with PInvoke Pinned Object APIs
+/*coverage: GetPinnedHandle(); FreePinnedHandle(); GetPinnedObject()
+/*          Finalize
+/******************************************************************/
+
+namespace DefaultNamespace {
+
+    using System;
+    using System.Collections.Generic;
+    using System.Runtime.InteropServices;
+
+    internal class NDPinFinal
+    {
+        internal Object p;
+        internal GCHandle handle;
+
+        internal NDPinFinal (Object p, GCHandle h)
+        {
+            this.p = p;
+            handle = h;
+            NDPinFinal.cCreatObj++;
+        }
+
+        ~NDPinFinal()
+        {
+            if (handle.IsAllocated)
+            {
+                NDPinFinal.pinList[cFinalObj] = handle.Target;
+            }
+            handle.Free();
+            NDPinFinal.cFinalObj++;
+        }
+
+        internal static NDPinFinal m_n;
+        internal static Object m_o;
+        internal static Object[] pinList = null;
+        internal static int cFinalObj = 0;
+        internal static int cCreatObj = 0;
+
+
+        public static void CreateObj(int iObj) {
+
+            pinList = new Object[iObj];
+            m_o = new int[100];
+            for (int i = 0; i < iObj; i++)
+            {
+                m_o = new int[100];
+                m_n = new NDPinFinal (m_o, GCHandle.Alloc(m_o, GCHandleType.Pinned));
+            }
+        }
+
+        public static bool RunTest(int iObj)
+        {
+
+            GC.Collect();
+            if (m_o != m_n.p)
+            {
+                return false;
+            }
+
+            m_n = null;
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+            
+            for( int i=0; i< iObj; i++ )
+            {
+                pinList[i] = null;
+            }
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+           
+            if( cFinalObj == cCreatObj )
+            {
+                return true;
+            }
+            else
+            {
+                Console.Write(cCreatObj-cFinalObj);
+                Console.WriteLine (" objects have been finalized!" );
+                return false;
+            }
+
+        }
+
+        public static int Main( String [] args )
+        {
+            int iObj = 1000;
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            if( args.Length >= 1 )
+            {
+                try
+                {
+                    iObj = Int32.Parse( args[0] );
+                }
+                catch (FormatException)
+                {
+                    Console.WriteLine("Format exception");
+                    return 1;
+                }
+            }
+            
+
+
+            CreateObj(iObj);
+            if (RunTest(iObj))
+            {
+                Console.WriteLine("Test Passed!");
+                return 100;
+            }
+
+            Console.WriteLine("Test Failed!");
+            return 1;
+
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/NDPin/ndpinfinal.csproj b/src/coreclr/tests/src/GC/Scenarios/NDPin/ndpinfinal.csproj
new file mode 100644 (file)
index 0000000..e730421
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="NDPinFinal.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/RanCollect/app.config b/src/coreclr/tests/src/GC/Scenarios/RanCollect/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/RanCollect/rancollect.cs b/src/coreclr/tests/src/GC/Scenarios/RanCollect/rancollect.cs
new file mode 100644 (file)
index 0000000..2697609
--- /dev/null
@@ -0,0 +1,377 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**************************************************************************
+/*Test: RanCollect
+/*args: iRep--the repeat times of alloc and delete
+/*  iObj--max elements' number for every collection object
+/*  iBigSize -- max Bignode's size. (10 <-->4MB)
+/*  iSeed -- seed of random generator, for getting random elements' number
+/*Description:This test use collection objects (L_ArrList2, L_Queue, L_ArrList1) and
+/*  Variant(L_Vart). It has iRep loops. Inside every loop, create random number
+/*  elements in Collection Objects and Variant Object.every element's size
+/*  is random, from 0 to iBigSize*iBigSize*10*4KB, for very loop, it also
+/*  delete random number elements or all the objects. samply change the four
+/*  arguments, you can get handreds of GC condition.
+/****************************************************************************/
+
+namespace DefaultNamespace {
+    using System;
+    //using System.Collections.Generic;
+
+    internal class RanCollect
+    {
+        public static int Main(String [] Args)
+        {
+            int iRep = 0;
+            int iObj = 0;
+            int iBigSize = 0;
+            int iSeed = 0;
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            if (Args.Length == 4)
+            {
+                if (!Int32.TryParse( Args[0], out iRep) ||
+                    !Int32.TryParse( Args[1], out iObj) ||
+                    !Int32.TryParse( Args[2], out iBigSize ) ||
+                    !Int32.TryParse( Args[3], out iSeed ) )
+                    {
+                        return 1;
+                    }
+            }
+            else
+            {
+                iRep = 10;
+                iObj = 100;
+                iBigSize = 2;
+                iSeed = 49;
+            }
+
+            if(iObj <= 10)
+            {
+                Console.WriteLine("the second argument must be larger than 10.");
+                return 1;
+            }
+
+            Console.Write("iRep= ");
+            Console.Write(iRep);
+            Console.Write(" ; iObj= ");
+            Console.Write(iObj);
+            Console.Write(" ; iBigSize=");
+            Console.Write(iBigSize);
+            Console.Write(" ; iSeed = ");
+            Console.WriteLine(iSeed);
+
+            RanCollect Mv_Obj = new RanCollect();
+
+            if(Mv_Obj.runTest(iRep, iObj, iBigSize, iSeed))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+
+            Console.WriteLine("Test Failed");
+            return 1;
+        }
+
+
+        public virtual bool runTest(int iRep, int iObj, int iBigSize, int iSeed)
+        {
+
+            ArrayList L_ArrList1 = new ArrayList();  //whose node is big double link object (DoubLinkBig).
+            ArrayList L_ArrList2 = new ArrayList();   //whose node is MinNode .
+            Queue L_Queue = new Queue();    //Whose node is DLRanBigNode.
+            Random r = new Random(iSeed);
+
+            int num = r.Next (10, iObj-1);
+            int delnum;
+            Object [] L_Vart = null;
+
+            Console.Write(num);
+            Console.WriteLine (" number's elements in collection objects");
+            for(int i=0; i<iRep;i++)
+            {
+                /*allocate memory*/
+                L_Vart = new Object[num];
+
+                for(int j=0; j<num; j++)
+                {
+                    int Size= r.Next(3, num); //the size of nodes.
+                    /*L_ArrList1 element's size is from 0 to iBigSize*iBigSize*10*4KB*/
+                    L_ArrList1.Add(new DoubLinkBig(r.Next(iBigSize)));
+
+                    /*L_ArrList2 element's size is Size number bytes;*/
+                    L_ArrList2.Add( new MinNode(Size));
+
+                    /*L_Queue element's size is from 0 to 1M*/
+                    L_Queue.Enqueue(new DLRanBigNode(250, null, null));
+
+                    if(j%6==0)
+                    {
+                        L_Vart[j] = (new DLRanBigNode(250, null, null));
+                    }
+                    else
+                    {
+                        L_Vart[j] = (new MinNode(Size));
+                    }
+
+                    L_ArrList1.RemoveAt(0);
+                }
+
+                /*start to make leak*/
+
+                if(r.Next(1, iRep)/3 == 0 || num < iObj/8)  //learn all the nodes
+                {
+                    num = r.Next(10, iObj-1);
+
+                    L_ArrList1 = new ArrayList();  //whose node is big double link object (DoubLinkBig).
+                    L_ArrList2 = new ArrayList();   //whose node is MinNode .
+                    L_Queue = new Queue();  //Whose node is DLRanBigNode.
+                    Console.WriteLine("all objects were deleted at the end of loop {0}",i);
+                    Console.WriteLine ("{0} number's elements in every collection objects in loop {1}", num, (i+1));
+                }
+                else
+                {
+                    if (L_ArrList2.Count <=1)
+                    {
+                        delnum = 1;
+                    }
+                    else
+                    {
+                        delnum = r.Next (1, L_ArrList2.Count);  //going to delete delnum nodes
+                    }
+
+                    if (delnum > (L_ArrList2.Count*3/4))
+                    {
+                        delnum = L_ArrList2.Count/2;
+                    }
+                    num = L_ArrList2.Count - delnum;   //going to add num nodes
+
+                    for(int j=0; j<delnum; j++)
+                    {
+                        L_ArrList2.RemoveAt(0);
+                        L_Queue.Dequeue();
+                    }
+                    Console.WriteLine("{0} were deleted in each collections at the end of loop {1}", delnum, i);
+                    Console.WriteLine ("{0} elements in each collection objects in loop ", num*2, (i+1));
+
+                }
+
+            }
+
+            return true;
+        }
+    }
+
+    public class DoubLinkBig
+    {
+        internal DLRanBigNode[] Mv_DLink;
+        internal int NodeNum;
+        public DoubLinkBig(int Num)
+        {
+            NodeNum = Num;
+            Mv_DLink = new DLRanBigNode[Num];
+
+            if (Num == 0)
+            {
+                return;
+            }
+
+            if (Num == 1)
+            {
+                Mv_DLink[0] = new DLRanBigNode(Num * 10, Mv_DLink[0], Mv_DLink[0]);
+                return;
+            }
+
+            Mv_DLink[0] = new DLRanBigNode(Num * 10, Mv_DLink[Num - 1], Mv_DLink[1]);
+            for (int i = 1; i < Num - 1; i++)
+            {
+                Mv_DLink[i] = new DLRanBigNode(Num * 10, Mv_DLink[i - 1], Mv_DLink[i + 1]);
+            }
+            Mv_DLink[Num - 1] = new DLRanBigNode(Num * 10, Mv_DLink[Num - 2], Mv_DLink[0]);
+
+        }
+
+        public virtual int GetNodeNum()
+        {
+            return NodeNum;
+        }
+    }
+
+    internal class MinNode
+    {
+        public MinNode(int size)
+        {
+
+            byte[] obj = new byte[size];
+
+            if (size > 0)
+            {
+                obj[0] = (byte)10;
+                if (size > 1)
+                {
+                    obj[size - 1] = (byte)11;
+                }
+            }
+
+        }
+    }
+
+    public class DLRanBigNode
+    {
+        // disabling unused variable warning
+#pragma warning disable 0414
+        internal DLRanBigNode Last;
+        internal DLRanBigNode Next;
+        internal int[] Size;
+#pragma warning restore 0414
+
+        internal static int FACTOR = 1024;
+
+        public DLRanBigNode(int SizeNum, DLRanBigNode LastObject, DLRanBigNode NextObject)
+        {
+            Last = LastObject;
+            Next = NextObject;
+            Random r = new Random(10);
+            Size = new int[FACTOR * r.Next(SizeNum)];
+        }
+    }
+
+
+    //Queue implemented as a circular array
+    class Queue
+    {
+        int m_Capacity = 20; //default capacity
+        int m_Size = 0;
+        Object[] m_Array;
+        int m_First = 0;
+        int m_Last = -1;
+
+        public Queue()
+        {
+            m_Array = new Object[m_Capacity];
+        }
+        public Queue(int capacity)
+        {
+            m_Capacity = capacity;
+            m_Array = new Object[m_Capacity];
+        }
+        public int Count
+        {
+            get
+            {
+                return m_Size;
+            }
+        }
+       
+        public void Enqueue(Object obj)
+        {
+            if(m_Size >= m_Capacity) //array full; increase capacity
+            {
+                int newCapacity = m_Capacity * 2;
+                Object[] newArray = new Object[newCapacity];
+
+                int current = m_First;
+                for (int i = 0; i < m_Size; i++)
+                {
+                    newArray[0] = m_Array[current];
+                    current = (current+1) % m_Capacity;
+                }
+                m_Array = newArray;
+                m_First = 0;
+                m_Last = m_Size - 1;
+                m_Capacity = newCapacity;
+            }
+           
+            m_Last++;
+            if(m_Last == m_Capacity) //wrap around 
+                m_Last = m_Last % m_Capacity;
+            m_Array[m_Last] = obj;
+            m_Size++;
+        }
+
+        public Object Dequeue()
+        {
+            if (m_Size == 0)
+                throw new InvalidOperationException();
+
+            Object returnObject = m_Array[m_First];
+            m_Array[m_First] = null;
+            m_First = (m_First+1) % m_Capacity;
+            m_Size--;
+            return returnObject;
+        }
+    }
+
+    class ArrayList
+    {
+        int m_Capacity = 20; //default capacity
+        int m_Size = 0;
+        Object[] m_Array;
+
+        public ArrayList()
+        {
+            m_Array = new Object[m_Capacity];
+        }
+        public ArrayList(int capacity)
+        {
+            m_Capacity = capacity;
+            m_Array = new Object[m_Capacity];
+        }
+
+        public int Count
+        {
+            get
+            {
+                return m_Size;
+            }
+        }
+
+        public int Capacity
+        {
+            get
+            {
+                return m_Capacity;
+            }
+        }
+
+        //Add an Object; returns the array index at which the object was added;
+        public int Add(Object obj)
+        {
+
+            if (m_Size >= m_Capacity) //increase capacity
+            {
+                int newCapacity = m_Capacity * 2;
+                Object[] newArray = new Object[newCapacity];
+                for (int i = 0; i < m_Size; i++)
+                {
+                    newArray[i] = m_Array[i];
+                }
+                m_Array = newArray;
+                m_Capacity = newCapacity;
+            }
+
+           
+            m_Array[m_Size] = obj;
+            m_Size++;
+            return (m_Size - 1);
+       
+        }
+
+        public void RemoveAt(int position)
+        {
+            if (position < 0 || position >= m_Size)
+                throw new ArgumentOutOfRangeException();
+
+            m_Array[position] = null;
+
+            //shift elements to fill the empty slot
+            for (int i = position; i < m_Size-1; i++)
+            {
+                m_Array[i] = m_Array[i + 1];
+            }
+            m_Size--;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/RanCollect/rancollect.csproj b/src/coreclr/tests/src/GC/Scenarios/RanCollect/rancollect.csproj
new file mode 100644 (file)
index 0000000..8757338
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>7 40 4 77</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="RanCollect.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/ReflectObj/app.config b/src/coreclr/tests/src/GC/Scenarios/ReflectObj/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/ReflectObj/reflectobj.cs b/src/coreclr/tests/src/GC/Scenarios/ReflectObj/reflectobj.cs
new file mode 100644 (file)
index 0000000..b3cc55b
--- /dev/null
@@ -0,0 +1,132 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**************************************************************/
+/* TEST: ReflectObj
+/* Purpose: test if GC can handle objects create by reflect
+/* Coverage:    Class.CreateInstance()
+/*              Class.GetField()
+/*              Class.GetConstructor()
+/*              ConstructorInfo.Invoke()
+/*              FieldInfo.SetValue()
+/*              FieldInfo.IsStatic()
+/*              FieldInfo.Ispublic()
+/**************************************************************/
+
+namespace App {
+    using System;
+    using System.Reflection;
+    using System.Collections.Generic;
+
+    class ReflectObj
+    {
+        Object obj;
+        public static int icCreat = 0;
+        public static int icFinal = 0;
+        public static List<object> al = new List<object>( );
+        public ReflectObj()
+        {
+            obj = new long[1000];
+            icCreat++;
+        }
+
+        public ReflectObj( int l )
+        {
+            obj = new long[l];
+            icCreat++;
+        }
+
+        public Object GetObj()
+        {
+            return obj;
+        }
+
+        ~ReflectObj()
+        {
+            al.Add( GetObj() );
+            icFinal++;
+        }
+
+        public static int Main( String [] str )
+        {
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+            CreateObj temp = new CreateObj();
+            if (temp.RunTest())
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            Console.WriteLine("Test Failed");
+            return 1;
+        }
+
+        class CreateObj
+        {
+            private Object[] v;
+            private Type myClass;
+            private Type [] rtype;
+            private ConstructorInfo CInfo;
+
+            public CreateObj()
+            {
+                myClass = Type.GetType( "App.ReflectObj" );
+                v = new Object[1];
+                for( int i=0; i< 2000; i++ )
+                {
+                    v[0] = i;
+                    Activator.CreateInstance(myClass, v );
+                }
+            }
+
+            public bool RunTest()
+            {
+                bool retVal = false;
+                GC.Collect();
+                GC.WaitForPendingFinalizers();
+                GC.Collect();
+
+                Console.WriteLine("Created Objects: {0} Finalized objects: {1}",icCreat, icFinal );
+                if ( icFinal != icCreat )
+                {
+                    return false;
+                }
+
+                FieldInfo fInfo = myClass.GetField( "icCreat", BindingFlags.IgnoreCase);
+                fInfo = myClass.GetField( "icFinal", BindingFlags.IgnoreCase);
+
+                Console.WriteLine( "Fieldinfo done" ); //debug;
+
+                CreateMoreObj();
+
+                GC.Collect();
+                GC.WaitForPendingFinalizers();
+                GC.Collect();
+
+                retVal = (icFinal == icCreat );
+
+                Console.WriteLine("Living objects: "+ ReflectObj.al.Count );
+                ReflectObj.al = null;
+
+                return retVal;
+
+            }
+
+            public void CreateMoreObj()
+            {
+                rtype = new Type[0];
+                CInfo = myClass.GetConstructor(rtype );
+
+                for( int i=0; i< 2000; i++ )
+                {
+                    CInfo.Invoke((Object[])null );
+                }
+            }
+
+
+        }
+
+
+    }
+
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/ReflectObj/reflectobj.csproj b/src/coreclr/tests/src/GC/Scenarios/ReflectObj/reflectobj.csproj
new file mode 100644 (file)
index 0000000..80af403
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="ReflectObj.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/Resurrection/app.config b/src/coreclr/tests/src/GC/Scenarios/Resurrection/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/Resurrection/continue.cs b/src/coreclr/tests/src/GC/Scenarios/Resurrection/continue.cs
new file mode 100644 (file)
index 0000000..f071a55
--- /dev/null
@@ -0,0 +1,139 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace DefaultNamespace {
+    using System;
+   
+
+    internal class Continue
+    {
+// disabling unused variable warning
+#pragma warning disable 0414
+        internal static Object StObj;
+
+        public class CreateObj
+        {
+            BNode obj;
+#pragma warning restore 0414
+            public CreateObj()
+            {
+                Continue mv_Obj = new Continue();
+
+                for( int i=1; i< 1000; i++)
+                {
+                    obj = new BNode(i); //create new one and delete the last one.
+                    mv_Obj.CreateNode( i ); //create locate objects in createNode().
+                }
+
+                Console.Write(BNode.icCreateNode); 
+                Console.WriteLine(" Nodes were created.");
+            }
+
+
+            public bool RunTest()
+            {
+                obj = null;
+                GC.Collect();
+                GC.WaitForPendingFinalizers();
+                GC.Collect();
+
+                Console.Write(BNode.icFinalNode); 
+                Console.WriteLine(" Nodes were finalized and resurrected.");
+
+                for (int i = 0; i < BNode.rlNodeCount; i++)
+                {
+                    BNode oldNode = (BNode)BNode.rlNode[i];
+                    if ( oldNode.mem[0] != 99 )
+                    {
+                        Console.WriteLine( "One Node is not resurrected correctly.");
+                    }
+                    oldNode = null;
+                    BNode.rlNode[ i ] = null;
+                }
+
+                GC.Collect();
+                GC.WaitForPendingFinalizers();
+                GC.Collect();
+
+                return ( BNode.icCreateNode == BNode.icFinalNode );
+
+            }
+
+        }
+
+        public static int Main()
+        {
+
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+            CreateObj temp = new CreateObj();
+
+            if(temp.RunTest())
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            Console.WriteLine("Test Failed");
+            return 1;
+        }
+
+
+        ~Continue()
+        {
+            Continue.StObj = ( this );
+            Console.WriteLine( "Main class Finalize().");
+
+        }
+
+        public void CreateNode( int i )
+        {
+            BNode rgobj = new BNode( i );
+        }
+    }
+
+
+    internal class BNode
+    {
+        public static int icCreateNode = 0;
+        public static int icFinalNode = 0;
+        public static int rlNodeCapacity = 2000;
+        public static int rlNodeCount = 0;
+        internal static BNode[] rlNode = new BNode[rlNodeCapacity];
+        public int [] mem;
+        public BNode( int i )
+        {
+
+            icCreateNode++;
+
+            mem = new int[i];
+            mem[0] = 99;
+            if(i > 1 )
+            {
+                mem[mem.Length-1] = mem.Length-1;
+            }
+
+
+        }
+
+
+        ~BNode()
+        {
+            icFinalNode++;
+
+            //resurrect objects
+            if (rlNodeCount == rlNodeCapacity)
+            {
+                rlNodeCapacity = rlNodeCapacity * 2;
+                BNode[] newrlNode = new BNode[rlNodeCapacity*2];
+
+                for (int i = 0; i < rlNodeCount; i++)
+                {
+                    newrlNode[i] = rlNode[i];
+                }
+                rlNode = newrlNode;
+            }
+            rlNode[rlNodeCount] = this;
+            rlNodeCount++;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Resurrection/continue.csproj b/src/coreclr/tests/src/GC/Scenarios/Resurrection/continue.csproj
new file mode 100644 (file)
index 0000000..ee75dc4
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="Continue.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/Rootmem/app.config b/src/coreclr/tests/src/GC/Scenarios/Rootmem/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/Rootmem/rootmem.cs b/src/coreclr/tests/src/GC/Scenarios/Rootmem/rootmem.cs
new file mode 100644 (file)
index 0000000..b11d6d5
--- /dev/null
@@ -0,0 +1,91 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*******************************************************************/
+/* Test: RootMem
+/* Purpose: Test if Root class manage memory correctly against GC
+/* Coverage:    Root.Alloc(), Root.Free(), Root.Get()
+/*******************************************************************/
+
+namespace DefaultNamespace {
+    using System;
+    using System.Runtime.InteropServices;
+
+    internal class RootMem
+    {
+        internal long [] l;
+        internal static GCHandle [] root;
+        internal static int n;
+
+        public static int Main( String [] args )
+        {
+            int iSize = 1000;
+            Object [] arVar = new Object[iSize];
+            root = new GCHandle[iSize];
+            RootMem rm_obj;
+
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            for( n=0; n< iSize; n++ )
+            {
+                 rm_obj = new RootMem( n );
+                 root[n] = GCHandle.Alloc(rm_obj );
+            }
+            //Console.WriteLine("After save objects to Root and before GCed: "+GC.GetTotalMemory(false) );
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+            //Console.WriteLine("After save objects to Root and after GCed: "+GC.GetTotalMemory(false) );
+
+            Object v;
+            for( int i=0; i< iSize; i++)
+            {
+                v = ( root[i]) ;
+            }
+            //Console.WriteLine("After Get objects from root and before GCed: "+GC.GetTotalMemory(false) );
+            GC.Collect();
+            //Console.WriteLine("After Get objects from root and after GCed: "+GC.GetTotalMemory(false) );
+
+            for( int i=0; i<iSize; i++ )
+            {
+                root[i].Free();
+            }
+            //Console.WriteLine("After free root and before GCed: "+GC.GetTotalMemory(false) );
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+            //Console.WriteLine("After free root and after GCed: "+GC.GetTotalMemory(false) );
+            try
+            {
+                for( int i=0; i<iSize; i++ )
+                {
+                    arVar[i]= ( root[i].Target  );
+                }
+            }
+            catch(System.InvalidOperationException)
+            {
+                //expected exception is throw after gchandles were free
+                Console.WriteLine("test Passed");
+                return 100;
+            }
+
+            Console.WriteLine("test failed");
+            return 1;
+        }
+
+        public RootMem( int i )
+        {
+            if( i> 0)
+            {
+                l = new long[i];
+                l[0] = 0;
+                l[i-1] = i;
+            }
+        }
+
+        ~RootMem()
+        {
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/Rootmem/rootmem.csproj b/src/coreclr/tests/src/GC/Scenarios/Rootmem/rootmem.csproj
new file mode 100644 (file)
index 0000000..4cdf6f2
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="RootMem.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/Samples/app.config b/src/coreclr/tests/src/GC/Scenarios/Samples/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/Samples/gc.cs b/src/coreclr/tests/src/GC/Scenarios/Samples/gc.cs
new file mode 100644 (file)
index 0000000..a6c1cfe
--- /dev/null
@@ -0,0 +1,532 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*=====================================================================
+  File:      GC.cs
+
+  Summary:   Demonstrates how the garbage collector works.
+
+---------------------------------------------------------------------
+  This file is part of the Microsoft COM+ 2.0 SDK Code Samples.
+
+  Copyright (C) 2000 Microsoft Corporation.  All rights reserved.
+
+This source code is intended only as a supplement to Microsoft
+Development Tools and/or on-line documentation.  See these other
+materials for detailed information regarding Microsoft code samples.
+
+THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+PARTICULAR PURPOSE.
+=====================================================================*/
+
+
+// Add the classes in the following namespaces to our namespace
+using System;
+using System.Threading;
+
+
+///////////////////////////////////////////////////////////////////////////////
+
+
+// Note that deriving from Object is optional since it is always implied
+public class BaseObj : Object {
+    private String name;    // Each object has a name to help identify it
+
+    // Note that explicitly calling the base class's constructor is
+    // optional since the compiler ensures it anyway.
+    // Also note that there is no concept of a destructor.
+    public BaseObj(String name) : base() {
+        this.name = name;
+        Display("BaseObj Constructor");
+    }
+
+    public void Display(String status) {
+        Application.Display(String.Format("Obj({0}): {1}", name, status));
+    }
+
+    // A Finalize method is the closest thing to a destructor but many of the
+    // semantics are different. The demos in this application demonstrate this.
+    //protected override void Finalize() {
+    ~BaseObj() {
+        Display("BaseObj Finalize");
+
+        // If possible, do not have a Finalize method for your class. Finalize
+        // methods usually run when the heap is low on available storage
+        // and needs to be garbage collected. This can hurt application 
+        // performance significantly.
+
+        // If you must implement a Finalize method, make it run fast, avoid
+        // synchronizing on other threads, do not block, and 
+        // avoid raising any exceptions (although the Finalizer thread 
+        // automatically recovers from any unhandled exceptions).
+
+        // NOTE: In the future, exceptions may be caught using an 
+        // AppDomain-registered unhandled Finalize Exception Handler
+
+        // While discouraged, you may call methods on object's referred
+        // to by this object. However, you must be aware that the other
+        // objects may have already had their Finalize method called 
+        // causing these objects to be in an unpredictable state.
+        // This is because the system does not guarantees that
+        // Finalizers will be called in any particular order.
+    }
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+
+
+// This class shows how to derive a class from another class and how base class
+// Finalize methods are NOT automatically called. By contrast, base class 
+// destructors (in unmanaged code) are automatically called. 
+// This is one example of how destructors and Finalize methods differ.
+public class DerivedObj : BaseObj {
+    public DerivedObj(String s) : base(s) {
+        Display("DerivedObj Constructor");
+    }
+
+    //protected override void Finalize() {
+      ~DerivedObj() {    
+        Display("DerivedObj Finalize");
+
+        // The GC has a special thread dedicated to executing Finalize 
+        // methods. You can tell that this thread is different from the 
+        // application's main thread by comparing the thread's hash codes.
+        Display("Finalize thread's hash code: " 
+            + Thread.CurrentThread.GetHashCode());
+
+        // BaseObj's Finalize is NOT called unless you execute the line below
+        // base.Finalize();        //commented by vaishak due to breaking change
+    }
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+
+
+// This class shows how an object can resurrect itself
+public class ResurrectObj : BaseObj {
+
+    // Indicates if object should resurrect itself when collected
+    private Boolean allowResurrection = true;   // Assume resurrection
+
+    public ResurrectObj(String s) : base(s) {
+        Display("ResurrectObj Constructor");
+    }
+
+    public void SetResurrection(Boolean allowResurrection) {
+        this.allowResurrection = allowResurrection;
+    }
+
+    //protected override void Finalize() {
+      ~ResurrectObj() {
+        Display("ResurrectObj Finalize");
+        if (allowResurrection) {
+            Display("This object is being resurrected");
+            // Resurrect this object by making something refer to it
+            Application.ResObjHolder = this;
+
+            // When the GC calls an object's Finalize method, it assumes that
+            // there is no need to ever call it again. However, we've now 
+            // resurrected this object and the line below forces the GC to call
+            // this object's Finalize again when the object is destroyed again.
+            // BEWARE: If ReRegisterForFinalize is called multiple times, the 
+            // object's Finalize method will be called multiple times.
+            GC.ReRegisterForFinalize(this);
+
+            // If this object contains a member referencing another object,
+            // The other object may have been finalized before this object
+            // gets resurrected. Note that resurrecting this object forces
+            // the referenced object to be resurrected as well. This object
+            // can continue to use the referenced object even though it was
+            // finalized.
+            
+        } else {
+            Display("This object is NOT being resurrected");
+        }
+    }
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+
+
+// This class shows how the GC improves performance using generations
+public class GenObj : BaseObj {
+    public GenObj(String s) : base(s) {
+        Display("GenObj Constructor");
+    }
+
+    public void DisplayGeneration() {
+        Display(String.Format("Generation: {0}", GC.GetGeneration(this)));
+    }
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+
+
+// This class shows the proper way to implement explicit cleanup.
+public class DisposeObj : BaseObj {
+    public DisposeObj(String s) : base(s) {
+        Display("DisposeObj Constructor");
+    }
+
+    // When an object of this type wants to be explicitly cleaned-up, the user 
+    // of this object should call Dispose at the desired code location.
+    public void Dispose() {
+        Display("DisposeObj Dispose");
+        // Usually Dispose() calls Finalize so that you can
+        // implement all the cleanup code in one place.
+        // Finalize();    //commented by vaishak due to breaking change
+
+        // Tell the garbage collector that the object doesn't require any
+        // cleanup when collected since Dispose was called explicitly.
+        GC.SuppressFinalize(this);
+    }
+
+    // Put the object cleanup code in the Finalize method
+    //protected override void Finalize() {
+    ~DisposeObj(){
+        Display("DisposeObj Finalize");
+        // This function can be called by Dispose() or by the GC
+        // If called by Dispose, the application's thread executes this code
+        // If called by the GC, then a special GC thread executes this code
+    }
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+
+
+// This class represents the application itself
+class Application {
+    static private int indent = 0;
+
+    static public void Display(String s) { 
+        for (int x = 0; x < indent * 3; x++)
+            Console.Write(" ");
+        Console.WriteLine(s);
+    }
+
+    static public void Display(int preIndent, String s, int postIndent) {
+        indent += preIndent;
+        Display(s);
+        indent += postIndent;
+    }
+
+    static public void Collect() {
+        Display(0, "Forcing a garbage collection", 0);
+        GC.Collect();
+    }
+
+    static public void Collect(int generation) {
+        Display(0, "Forcing a garbage collection of generation " + generation, 0);
+        GC.Collect(generation);
+    }
+
+    static public void WaitForFinalizers() {
+        Display(0, "Waiting for Finalizers to complete", +1);
+        GC.WaitForPendingFinalizers();
+        Display(-1, "Finalizers are complete", 0);
+    }
+
+    // This method demonstrates how the GC works.
+    private static void Introduction() {
+        Display(0, "\n\nDemo start: Introduction to Garbage Collection.", +1);
+
+        // Create a new DerivedObj in the managed heap
+        // Note: Both BaseObj and DerivedObj constructors are called
+        DerivedObj obj = new DerivedObj("Introduction");
+
+        obj = null; // We no longer need this object
+
+        // The object is unreachable so forcing a GC causes it to be finalized.
+        Collect();
+
+        // Wait for the GC's Finalize thread to finish 
+        // executing all queued Finalize methods.
+        WaitForFinalizers();
+        // NOTE: The GC calls the most-derived (farthest away from 
+        // the Object base class) Finalize only.
+        // Base class Finalize functions are called only if the most-derived
+        // Finalize method explicitly calls its base class's Finalize method.
+
+        // This is the same test as above with one slight variation
+        obj = new DerivedObj("Introduction");
+        // obj = null; // Variation: this line is commented out
+        Collect();
+        WaitForFinalizers();    
+        // Notice that we get identical results as above: the Finalize method 
+        // runs because the jitter's optimizer knows that obj is not 
+        // referenced later in this function.
+
+        Display(-1, "Demo stop: Introduction to Garbage Collection.", 0);
+    }
+
+
+    // This reference is accessed in the ResurrectObj.Finalize method and
+    // is used to create a strong reference to an object (resurrecting it).
+    static public ResurrectObj ResObjHolder;    // Defaults to null
+
+
+    // This method demonstrates how the GC supports resurrection.
+    // NOTE: Resurrection is discouraged.
+    private static void ResurrectionDemo() {
+        Display(0, "\n\nDemo start: Object Resurrection.", +1);
+
+        // Create a ResurrectionObj
+        ResurrectObj obj = new ResurrectObj("Resurrection");
+
+        // Destroy all strong references to the new ResurrectionObj
+        obj = null;
+
+        // Force the GC to determine that the object is unreachable.
+        Collect();
+        WaitForFinalizers(); // You should see the Finalize method called.
+
+        // However, the ResurrectionObj's Finalize method 
+        // resurrects the object keeping it alive. It does this by placing a 
+        // reference to the dying-object in Application.ResObjHolder
+
+        // You can see that ResurrectionObj still exists because
+        // the following line doesn't raise an exception.
+        ResObjHolder.Display("Still alive after Finalize called");
+
+        // Prevent the ResurrectionObj object from resurrecting itself again, 
+        ResObjHolder.SetResurrection(false);
+
+        // Now, let's destroy this last reference to the ResurrectionObj
+        ResObjHolder = null;
+
+        // Force the GC to determine that the object is unreachable.
+        Collect();
+        WaitForFinalizers(); // You should see the Finalize method called.
+        Display(-1, "Demo stop: Object Resurrection.", 0);
+    }
+
+
+    // This method demonstrates how to implement a type that allows its users
+    // to explicitly dispose/close the object. For many object's this paradigm
+    // is strongly encouranged.
+    private static void DisposeDemo() {
+        Display(0, "\n\nDemo start: Disposing an object versus Finalize.", +1);
+        DisposeObj obj = new DisposeObj("Explicitly disposed");
+        obj.Dispose();  // Explicitly cleanup this object, Finalize should run
+        obj = null;
+        Collect();
+        WaitForFinalizers(); // Finalize should NOT run (it was suppressed)
+
+        obj = new DisposeObj("Implicitly disposed");
+        obj = null;
+        Collect();
+        WaitForFinalizers(); // No explicit cleanup, Finalize SHOULD run
+        Display(-1, "Demo stop: Disposing an object versus Finalize.", 0);
+    }
+
+
+    // This method demonstrates the unbalanced nature of ReRegisterForFinalize
+    // and SuppressFinalize. The main point is if your code makes multiple
+    // calls to ReRegisterForFinalize (without intervening calls to 
+    // SuppressFinalize) the Finalize method may get called multiple times.
+    private static void FinalizationQDemo() {
+        Display(0, "\n\nDemo start: Suppressing and ReRegistering for Finalize.", +1);
+        // Since this object has a Finalize method, a reference to the object 
+        // will be added to the finalization queue.
+        BaseObj obj = new BaseObj("Finalization Queue"); 
+
+        // Add another 2 references onto the finalization queue
+        // NOTE: Don't do this in a normal app. This is only for demo purposes.
+        GC.ReRegisterForFinalize(obj);
+        GC.ReRegisterForFinalize(obj);
+
+        // There are now 3 references to this object on the finalization queue.
+
+        // Set a bit flag on this object indicating that it should NOT be finalized.
+        GC.SuppressFinalize(obj);
+
+        // There are now 3 references to this object on the finalization queue.
+        // If the object were unreachable, the 1st call to this object's Finalize 
+        // method will be discarded but the 2nd & 3rd calls to Finalize will execute.
+
+        // Sets the same bit effectively doing nothing!
+        GC.SuppressFinalize(obj);
+
+        obj = null;   // Remove the strong reference to the object.
+
+        // Force a GC so that the object gets finalized
+        Collect();
+        // NOTE: Finalize is called twice because only the 1st call is suppressed!
+        WaitForFinalizers(); 
+        Display(-1, "Demo stop: Suppressing and ReRegistering for Finalize.", 0);
+    }
+
+
+    // This method demonstrates how objects are promoted between generations.
+    // Applications could take advantage of this info to improve performance
+    // but most applications will ignore this information.
+    private static void GenerationDemo() {
+        Display(0, "\n\nDemo start: Understanding Generations.", +1);
+
+        // Let's see how many generations the managed heap supports (we know it's 2)
+        Display("Maximum GC generations: " + GC.MaxGeneration);
+
+        // Create a new BaseObj in the heap
+        GenObj obj = new GenObj("Generation");
+
+        // Since this object is newly created, it should be in generation 0
+        obj.DisplayGeneration();    // Displays 0
+
+        // Performing a GC promotes the object's generation
+        Collect();
+        obj.DisplayGeneration();    // Displays 1
+
+        Collect();
+        obj.DisplayGeneration();    // Displays 2
+
+        Collect();
+        obj.DisplayGeneration();    // Displays 2   (max generation)
+
+        obj = null;             // Destroy the strong reference to this object
+
+        Collect(0);             // Collect objects in generation 0
+        WaitForFinalizers();    // We should see nothing
+
+        Collect(1);             // Collect objects in generation 1
+        WaitForFinalizers();    // We should see nothing
+
+        Collect(2);             // Same as Collect()
+        WaitForFinalizers();    // Now, we should see the Finalize method run
+
+        Display(-1, "Demo stop: Understanding Generations.", 0);
+    }
+
+
+    // This method demonstrates how weak references (WR) work. A WR allows
+    // the GC to collect objects if the managed heap is low on memory.
+    // WRs are useful to apps that have large amounts of easily-reconstructed
+    // data that they want to keep around to improve performance. But, if the 
+    // system is low on memory, the objects can be destroyed and replaced when
+    // the app knows that it needs it again.
+    private static void WeakRefDemo(Boolean trackResurrection) {
+        Display(0, String.Format(
+            "\n\nDemo start: WeakReferences that {0}track resurrections.",
+            trackResurrection ? "" : "do not "), +1);
+
+        // Create an object
+        BaseObj obj = new BaseObj("WeakRef");
+
+        // Create a WeakReference object that refers to the new object
+        WeakReference wr = new WeakReference(obj, trackResurrection);
+
+        // The object is still reachable, so it is not finalized.
+        Collect();
+        WaitForFinalizers(); // The Finalize method should NOT execute
+        obj.Display("Still exists");
+
+        // Let's remove the strong reference to the object
+        obj = null;     // Destroy strong reference to this object
+
+        // The following line creates a strong reference to the object
+        obj = (BaseObj) wr.Target;
+        Display("Strong reference to object obtained: " + (obj != null));
+
+        obj = null;     // Destroy strong reference to this object again.
+
+        // The GC considers the object to be unreachable and collects it.
+        Collect();
+        WaitForFinalizers();    // Finalize should run.
+
+        // This object resurrects itself when its Finalize method is called.
+        // If wr is NOT tracking resurrection, wr thinks the object is dead
+        // If wr is tracking resurrection, wr thinks the object is still alive
+
+        // NOTE: If the object referred to by wr doesn't have a Finalize method,
+        // then wr would think that the object is dead regardless of whether 
+        // wr is tracking resurrection or not. For example:
+        //    Object obj = new Object();   // Object doesn't have a Finalize method
+        //    WeakReference wr = new WeakReference(obj, true);
+        //    obj = null;
+        //    Collect();
+        //    WaitForFinalizers();       // Does nothing
+        //    obj = (Object) wr.Target;  // returns null
+
+        // The following line attempts to create a strong reference to the object
+        obj = (BaseObj) wr.Target;
+        Display("Strong reference to object obtained: " + (obj != null));
+
+        if (obj != null) {
+            // The strong reference was obtained so this wr must be 
+            // tracking resurrection. At this point we have a strong
+            // reference to an object that has been finalized but its memory
+            // has not yet been reclaimed by the collector.
+            obj.Display("See, I'm still alive");
+
+            obj = null; // Destroy the strong reference to the object
+
+            // Collect reclaims the object's memory since this object 
+            // has no Finalize method registered for it anymore.
+            Collect();  
+            WaitForFinalizers();    // We should see nothing here
+
+            obj = (BaseObj) wr.Target;  // This now returns null
+            Display("Strong reference to object obtained: " + (obj != null));
+        }
+
+        // Cleanup everything about this demo so there is no affect on the next demo
+        obj = null;           // Destroy strong reference (if it exists)
+        wr = null;            // Destroy the WeakReference object (optional) 
+        Collect();
+        WaitForFinalizers();
+
+        // NOTE: You are dicouraged from using the WeakReference.IsAlive property
+        // because the object may be killed immediately after IsAlive returns
+        // making the return value incorrect. If the Target property returns 
+        // a non-null value, then the object is alive and will stay alive
+        // since you have a reference to it. If Target returns null, then the
+        // object is dead.
+        Display(-1, String.Format("Demo stop: WeakReferences that {0}track resurrections.", 
+            trackResurrection ? "" : "do not "), 0);
+    }
+
+    
+    public static int Main(String[] args) {
+    // Environment.ExitCode = 1;
+        Display("To fully understand this sample, you should step through the");
+        Display("code in the debugger while monitoring the output generated.\n");
+        Display("NOTE: The demos in this application assume that no garbage");
+        Display("      collections occur naturally. To ensure this, the sample");
+        Display("      objects are small in size and few are allocated.\n");
+        Display("Main thread's hash code: " + Thread.CurrentThread.GetHashCode());
+
+        Introduction();      // GC introduction
+        ResurrectionDemo();  // Demos object resurrection
+        DisposeDemo();       // Demos the use of Dispose & Finalize
+        FinalizationQDemo(); // Demos the use of SuppressFinalize & ReRegisterForFinalize
+        GenerationDemo();    // Demos GC generations
+        WeakRefDemo(false);  // Demos WeakReferences without resurrection tracking 
+        WeakRefDemo(true);   // Demos WeakReferences with resurrection tracking 
+        
+        // Demos Finalize on Shutdown symantics (this demo is inline) 
+        Display(0, "\n\nDemo start: Finalize on shutdown.", +1);
+
+        // Normally, when an application terminates, the GC does NOT collect and run finalizers.
+        // The line below forces the GC to do complete object cleanup
+        // GC.RequestFinalizeOnShutdown(); // For default behavior, comment out this line
+        // NOTE: Once you request FinalizeOnShutdown, you cannot change your mind.
+
+        // When Main returns, obj will have its Finalize method called.
+        BaseObj obj = new BaseObj("Shutdown");
+
+        // This is the last line of code executed before the application terminates.
+        Display(-1, "Demo stop: Finalize on shutdown (application is now terminating)", 0);
+   
+    return 100;
+    }
+}
+
+
+///////////////////////////////// End of File /////////////////////////////////
diff --git a/src/coreclr/tests/src/GC/Scenarios/Samples/gc.csproj b/src/coreclr/tests/src/GC/Scenarios/Samples/gc.csproj
new file mode 100644 (file)
index 0000000..c72b11b
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="GC.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/ServerModel/app.config b/src/coreclr/tests/src/GC/Scenarios/ServerModel/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/ServerModel/cache.cs b/src/coreclr/tests/src/GC/Scenarios/ServerModel/cache.cs
new file mode 100644 (file)
index 0000000..3ddd5c5
--- /dev/null
@@ -0,0 +1,87 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+namespace ServerSimulator
+{
+    /// <summary>
+    /// This class simulates a cache of user-defined size filled with 
+    /// arrays of objects of user-defined size, replacing them using either a FIFO or random algorithm
+    /// </summary>
+    internal sealed class Cache
+    {
+        private Object[] cache_list;
+        private int cache_length;
+        private int cache_item_size;
+        private int cache_item_count;
+        private bool fifo;
+        private int fifoIndex;
+
+        public Cache(bool fifo)
+        {
+            cache_item_size = (int)(ServerSimulator.Params.CacheSize * ServerSimulator.Params.CacheReplacementRate);
+            cache_length = (int)(1 / ServerSimulator.Params.CacheReplacementRate);
+            cache_list = new Object[cache_length];
+            cache_item_count = 0;
+            fifoIndex = 0;
+            this.fifo = fifo;
+        }
+
+        // fills an entry in the cache with an array of objects
+        public void Encache()
+        {
+            Object[] survivors = new Object[1 + cache_item_size / 100];
+
+            int volume = 0;
+            for (int i = 0; volume < cache_item_size; i++)
+            {
+                int alloc_surv = ServerSimulator.Rand.Next(100, 2000 + 2 * i);
+                survivors[i] = new byte[alloc_surv];
+                volume += alloc_surv;
+            }
+
+            int index;
+            if (fifo)
+            {
+                // use fifo cache replacement
+                index = fifoIndex;
+                fifoIndex++;
+                if (fifoIndex == cache_list.Length)
+                {
+                    fifoIndex = 0;
+                }
+            }
+            else
+            {
+                // use random cache replacement
+                index = ServerSimulator.Rand.Next(0, cache_length);
+            }
+
+            if (cache_list[index] == null)
+            {
+                cache_item_count++;
+            }
+            cache_list[index] = survivors;
+        }
+
+        // empties the cache
+        public void Clear()
+        {
+            for (int i = 0; i < cache_list.Length; i++)
+            {
+                cache_list[i] = null;
+            }
+        }
+
+        // returns true if the cache is full
+        public bool IsFull
+        {
+            get
+            {
+                return (cache_item_count == cache_length);
+            }
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/ServerModel/parameters.cs b/src/coreclr/tests/src/GC/Scenarios/ServerModel/parameters.cs
new file mode 100644 (file)
index 0000000..68f3cd9
--- /dev/null
@@ -0,0 +1,421 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using ServerSimulator.Properties;
+
+namespace ServerSimulator
+{
+
+    /// <summary>
+    /// This class validates and stores parameters passed in from the command-line or config file
+    /// </summary>
+    internal sealed class Parameters
+    {
+        //     the number of requests in flight
+        private int numRequests = 200;
+        public int NumRequests
+        {
+            get { return numRequests; }
+            set
+            {
+                if (value > 0)
+                {
+                    numRequests = value;
+                }
+                else
+                {
+                    throw new ArgumentOutOfRangeException("value", "NumRequests must be > 0");
+                }
+            }
+        }
+
+        //     the fraction of requests that are finalizable
+        private float finalizableRate = 0;
+        public float FinalizableRate
+        {
+            get { return finalizableRate; }
+            set
+            {
+                if ((value >= 0) && (value <= 1))
+                {
+                    finalizableRate = value;
+                }
+                else
+                {
+                    throw new ArgumentOutOfRangeException("value", "FinalizableRate must be >=0 and <=1");
+                }
+            }
+        }
+
+        //     the replacement rate of the cache for each request
+        private float cacheReplacementRate = 0.01f;
+        public float CacheReplacementRate
+        {
+            get { return cacheReplacementRate; }
+            set
+            {
+                if ((value > 0) && (value <= 1))
+                {
+                    cacheReplacementRate = value;
+                }
+                else
+                {
+                    throw new ArgumentOutOfRangeException("value", "CacheReplacementRate must be >0 and <=1");
+                }
+            }
+        }
+
+        //     the fraction that survives for the life of the request
+        private float survivalRate = 0.9f;
+        public float SurvivalRate
+        {
+            get { return survivalRate; }
+            set
+            {
+                if ((value > 0) && (value <= 1))
+                {
+                    survivalRate = value;
+                }
+                else
+                {
+                    throw new ArgumentOutOfRangeException("value", "SurvivalRate must be >0 and <=1");
+                }
+            }
+        }
+
+        //     the number of times to loop (-1 for infinite)
+        private int numPasses = -1;
+        public int NumPasses
+        {
+            get { return numPasses; }
+            set { numPasses = value; }
+        }
+
+        // the random seed for reproducibility
+        private int randomSeed = 0;
+        public int RandomSeed
+        {
+            get { return randomSeed; }
+            set { randomSeed = value; }
+        }
+
+        //     the total allocation per request in byte
+        private int allocationVolume = 100000;
+        public int AllocationVolume
+        {
+            get { return allocationVolume; }
+            set
+            {
+                if (value > 0)
+                {
+                    allocationVolume = value;
+                }
+                else
+                {
+                    throw new ArgumentOutOfRangeException("value", "AllocationVolume must be >0");
+                }
+            }
+        }
+
+        //     the cache size in bytes
+        private int cacheSize = 1024*1024*100;
+        public int CacheSize
+        {
+            get { return cacheSize; }
+            set
+            {
+                if (value > 0)
+                {
+                    cacheSize = value;
+                }
+                else
+                {
+                    throw new ArgumentOutOfRangeException("value", "CacheSize must be > 0");
+                }
+            }
+        }
+
+        //     the number of times requests to executes after steady state is achieved.
+        //     if it took 300 reqs to achieve steady state, then perform 300*steady_state_factor requests
+        private int steadyStateFactor = 20;
+        public int SteadyStateFactor
+        {
+            get { return steadyStateFactor; }
+            set
+            {
+                if (value > 0)
+                {
+                    steadyStateFactor = value;
+                }
+                else
+                {
+                    throw new ArgumentOutOfRangeException("value", "SteadyStateFactor must be > 0");
+                }
+            }
+        }
+
+        //     the amount of non changing static data in MB
+        private int staticDataVolume = 500;
+        public int StaticDataVolume
+        {
+            get { return staticDataVolume; }
+            set
+            {
+                if (value >= 0)
+                {
+                    staticDataVolume = value;
+                }
+                else
+                {
+                    throw new ArgumentOutOfRangeException("value", "StaticDataVolume must be >=0");
+                }
+            }
+        }
+
+        //      use fifo cache replacement strategy instead of random
+        private bool fifoCache = false;
+        public bool FifoCache
+        {
+            get { return fifoCache; }
+            set { fifoCache = value; }
+        }
+
+        //      pin all requests
+        private bool pinning = false;
+        public bool Pinning
+        {
+            get { return pinning; }
+            set { pinning = value; }
+        }
+
+        public Parameters()
+        {
+            numRequests = Settings.Default.NumRequests;
+            finalizableRate = Settings.Default.FinalizableRate;
+            cacheReplacementRate = Settings.Default.CacheReplacementRate;
+            survivalRate = Settings.Default.SurvivalRate;
+            numPasses = Settings.Default.NumPasses;
+            randomSeed = Settings.Default.RandomSeed;
+            allocationVolume = Settings.Default.AllocationVolume;
+            cacheSize = Settings.Default.CacheSize;
+            steadyStateFactor = Settings.Default.SteadyStateFactor;
+            staticDataVolume = Settings.Default.StaticDataVolume;
+            fifoCache = Settings.Default.FifoCache;
+            pinning = Settings.Default.Pinning;
+        }
+
+        // gets and stores command-line parameters
+        public bool GetParams(string[] args)
+        {
+            try
+            {
+                for (int i = 0; i < args.Length; i++)
+                {
+                    string str = args[i].ToLower();
+
+                    if (str.StartsWith("/randomseed:"))
+                    {
+                        int randomSeed = 0;
+                        if (!Int32.TryParse(str.Substring("/randomseed:".Length), out randomSeed))
+                        {
+                            Console.WriteLine("Invalid randomseed");
+                            return false;
+                        }
+                        else
+                        {
+                            //Console.WriteLine("randomseed: {0}", randomSeed);
+                            RandomSeed = randomSeed;
+                        }
+                    }
+                    else if (str.StartsWith("/finalizablerate:"))
+                    {
+                        float finalizableRate = 0;
+                        if (!float.TryParse(str.Substring("/finalizablerate:".Length), out finalizableRate))
+                        {
+                            Console.WriteLine("Invalid finalizablerate");
+                            return false;
+                        }
+                        else
+                        {
+                            //Console.WriteLine("finalizablerate: {0}", finalizableRate);
+                            this.finalizableRate = finalizableRate;
+                        }
+                    }
+                    else if (str.StartsWith("/cachereplacementrate:"))
+                    {
+                        float cacheReplacementRate = 0;
+                        if (!float.TryParse(str.Substring("/cachereplacementrate:".Length), out cacheReplacementRate))
+                        {
+                            Console.WriteLine("Invalid cachereplacementrate");
+                            return false;
+                        }
+                        else
+                        {
+                            //Console.WriteLine("cachereplacementrate: {0}", cacheReplacementRate);
+                            this.cacheReplacementRate = cacheReplacementRate;
+                        }
+                    }
+                    else if (str.StartsWith("/survivalrate:"))
+                    {
+                        float survivalRate = 0;
+                        if (!float.TryParse(str.Substring("/survivalrate:".Length), out survivalRate))
+                        {
+                            Console.WriteLine("Invalid survivalrate");
+                            return false;
+                        }
+                        else
+                        {
+                            //Console.WriteLine("survivalrate: {0}", survivalRate);
+                            this.survivalRate = survivalRate;
+                        }
+                    }
+                    else if (str.StartsWith("/numpasses:"))
+                    {
+                        int numPasses = 0;
+                        if (!Int32.TryParse(str.Substring("/numpasses:".Length), out numPasses))
+                        {
+                            Console.WriteLine("Invalid numpasses");
+                            return false;
+                        }
+                        else
+                        {
+                            //Console.WriteLine("numpasses: {0}", numPasses);
+                            this.numPasses = numPasses;
+                        }
+                    }
+                    else if (str.StartsWith("/allocationvolume:"))
+                    {
+                        int allocationVolume = 0;
+                        if (!Int32.TryParse(str.Substring("/allocationvolume:".Length), out allocationVolume))
+                        {
+                            Console.WriteLine("Invalid allocationvolume");
+                            return false;
+                        }
+                        else
+                        {
+                            //Console.WriteLine("allocationvolume: {0}", allocationVolume);
+                            this.allocationVolume = allocationVolume;
+                        }
+                    }
+                    else if (str.StartsWith("/cachesize:"))
+                    {
+                        int cacheSize = 0;
+                        if (!Int32.TryParse(str.Substring("/cachesize:".Length), out cacheSize))
+                        {
+                            Console.WriteLine("Invalid cachesize");
+                            return false;
+                        }
+                        else
+                        {
+                            //Console.WriteLine("cachesize: {0}", cacheSize);
+                            this.cacheSize = cacheSize;
+                        }
+                    }
+                    else if (str.StartsWith("/steadystatefactor:"))
+                    {
+                        int steadyStateFactor = 0;
+                        if (!Int32.TryParse(str.Substring("/steadystatefactor:".Length), out steadyStateFactor))
+                        {
+                            Console.WriteLine("Invalid steadystatefactor");
+                            return false;
+                        }
+                        else
+                        {
+                            //Console.WriteLine("steadystatefactor: {0}", steadyStateFactor);
+                            this.steadyStateFactor = steadyStateFactor;
+                        }
+                    }
+                    else if (str.StartsWith("/numrequests:"))
+                    {
+                        int numRequests = 0;
+                        if (!Int32.TryParse(str.Substring("/numrequests:".Length), out numRequests))
+                        {
+                            Console.WriteLine("Invalid numrequests");
+                            return false;
+                        }
+                        else
+                        {
+                            //Console.WriteLine("numrequests: {0}", numRequests);
+                            this.numRequests = numRequests;
+                        }
+                    }
+                    else if (str.StartsWith("/staticdatavolume:"))
+                    {
+                        int staticDataVolume = 0;
+                        if (!Int32.TryParse(str.Substring("/staticdatavolume:".Length), out staticDataVolume))
+                        {
+                            Console.WriteLine("Invalid staticdatavolume");
+                            return false;
+                        }
+                        else
+                        {
+                            //Console.WriteLine("staticdatavolume: {0}", staticDataVolume);
+                            this.staticDataVolume = staticDataVolume;
+                        }
+                    }
+                    else if (str.StartsWith("/fifocache:"))
+                    {
+                        int fifoCache = 0;
+                        if (!Int32.TryParse(str.Substring("/fifocache:".Length), out fifoCache))
+                        {
+                            Console.WriteLine("Invalid fifocache");
+                            return false;
+                        }
+                        else
+                        {
+                            // Console.WriteLine("fifocache: {0}", fifoCache);
+                            if (fifoCache == 0)
+                            {
+                                this.fifoCache = false;
+                            }
+                            else
+                            {
+                                this.fifoCache = true;
+                            }
+                        }
+                    }
+                    else if (str.StartsWith("/pinning:"))
+                    {
+                        int pinning = 0;
+                        if (!Int32.TryParse(str.Substring("/pinning:".Length), out pinning))
+                        {
+                            Console.WriteLine("Invalid pinning");
+                            return false;
+                        }
+                        else
+                        {
+                            //Console.WriteLine("pinning: {0}", pinning);
+                            if (pinning == 0)
+                            {
+                                this.pinning = false;
+                            }
+                            else
+                            {
+                                this.pinning = true;
+                            }
+                        }
+                    }
+                    else if (str.Equals("/?"))
+                    {
+                        return false;
+                    }
+                    else
+                    {
+                        Console.WriteLine("Invalid parameter");
+                        return false;
+                    }
+
+                }
+            }
+            catch (ArgumentOutOfRangeException e)
+            {
+                Console.WriteLine(e.Message);
+                return false;
+            }
+
+            return true;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/ServerModel/request.cs b/src/coreclr/tests/src/GC/Scenarios/ServerModel/request.cs
new file mode 100644 (file)
index 0000000..df116cd
--- /dev/null
@@ -0,0 +1,95 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace ServerSimulator
+{
+    /// <summary>
+    /// This class models a typical server request
+    /// </summary>
+    internal class Request
+    {
+        private Object[] survivors;
+        private GCHandle pin;
+
+        public Request()
+        {
+            survivors = new Object[1 + (int)(ServerSimulator.Params.AllocationVolume * ServerSimulator.Params.SurvivalRate) / 100];
+            int index = 0;
+            int volume = 0;
+
+            // allocate half of the request size.
+            while (volume < (int)(ServerSimulator.Params.AllocationVolume / 2))
+            {
+                volume += allocateRequest(index++);
+            }
+
+            // allocate one pinned buffer
+            if (ServerSimulator.Params.Pinning)
+            {
+                pin = GCHandle.Alloc(new byte[100], GCHandleType.Pinned);
+            }
+
+            // allocate the rest of the request
+            while (volume < ServerSimulator.Params.AllocationVolume)
+            {
+                volume += allocateRequest(index++);
+            }
+
+        }
+
+        // allocates the request along with garbage to simulate work on the server side
+        protected int allocateRequest(int index)
+        {
+            int alloc_surv = ServerSimulator.Rand.Next(100, 2000 + 2 * index);
+            int alloc = (int)(alloc_surv / ServerSimulator.Params.SurvivalRate) - alloc_surv;
+
+            // create garbage
+            int j = 0;
+            while (j < alloc)
+            {
+                int s = ServerSimulator.Rand.Next(10, 200 + 2 * j);
+                byte[] garbage = new byte[s];
+                j += s;
+            }
+
+            survivors[index] = new byte[alloc_surv];
+            return alloc_surv + alloc;
+        }
+
+        // deallocates the request
+        public void Retire()
+        {
+            if (pin.IsAllocated)
+            {
+                pin.Free();
+            }
+        }
+
+    }
+
+
+    /// <summary>
+    /// This class is a finalizable version of Request that allocates inside its finalizer
+    /// </summary>
+
+    internal sealed class FinalizableRequest : Request
+    {
+// disabling unused variable warning
+#pragma warning disable 0414
+        private byte[] finalizedData = null;
+#pragma warning restore 0414
+
+        public FinalizableRequest() : base()
+        {
+        }
+
+        ~FinalizableRequest()
+        {
+            finalizedData = new byte[ServerSimulator.Params.AllocationVolume];
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/ServerModel/server.cs b/src/coreclr/tests/src/GC/Scenarios/ServerModel/server.cs
new file mode 100644 (file)
index 0000000..fedd5af
--- /dev/null
@@ -0,0 +1,109 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+namespace ServerSimulator
+{
+    /// <summary>
+    /// This class simulates the server, which allocates static data for its lifetime,
+    /// fills the cache, creates and retires requests
+    /// </summary>
+    internal sealed class Server
+    {
+        private Object[] static_data;
+
+        public Server()
+        {
+            int volume = 0;
+
+            // static_data size in Mb
+            static_data = new Object[1 + ServerSimulator.Params.StaticDataVolume * 1000];
+
+            for (int i = 0; volume < static_data.Length; i++)
+            {
+                int alloc_surv = ServerSimulator.Rand.Next(1000, 20000 + 2 * i);
+                static_data[i] = new byte[alloc_surv];
+                volume += alloc_surv / 1000;
+            }
+
+        }
+
+        // creates requests until we reach the steady state with a full cache
+        public void OnePass()
+        {
+            int inst_requests = 0;
+            int total_reqs = 0;
+            int nreqs_to_steady = 0;
+            Request[] requests = new Request[ServerSimulator.Params.NumRequests];
+            Cache cache = new Cache(ServerSimulator.Params.FifoCache);
+            int start = Environment.TickCount;
+            int split = start;
+
+            while (true)
+            {
+                total_reqs++;
+
+                int i = ServerSimulator.Rand.Next(0, ServerSimulator.Params.NumRequests);
+                if (requests[i] != null)
+                {
+                    requests[i].Retire();
+                }
+                else
+                {
+                    inst_requests++;
+                }
+
+                // make every nth request finalizable
+                if (total_reqs % (1 / ServerSimulator.Params.FinalizableRate) == 0)
+                {
+                    requests[i] = new FinalizableRequest();
+                }
+                else
+                {
+                    requests[i] = new Request();
+                }
+
+                cache.Encache();
+
+                int stop = Environment.TickCount;
+
+                if ((stop - split) > 4000)
+                {
+                    Console.WriteLine("{0} reqs/sec", (total_reqs * 1000) / (stop - start));
+                    split = stop;
+                }
+
+                if (cache.IsFull && (inst_requests == ServerSimulator.Params.NumRequests))
+                {
+                    if (nreqs_to_steady == 0)
+                    {
+                        nreqs_to_steady = total_reqs;
+                        Console.WriteLine("took {0} iteration to reach steady state", nreqs_to_steady);
+                    }
+                    else if (total_reqs == ServerSimulator.Params.SteadyStateFactor * nreqs_to_steady)
+                    {
+                        break;
+                    }
+                }
+            }
+
+            for (int i = 0; i < requests.Length; i++)
+            {
+                if (requests[i] != null)
+                {
+                    requests[i].Retire();
+                }
+            }
+
+            int fstop = Environment.TickCount;
+            Console.WriteLine("{0} reqs/sec", (total_reqs * 1000) / (fstop - start));
+
+            //cleanup
+            static_data = null;
+            cache.Clear();
+
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/ServerModel/servermodel.cs b/src/coreclr/tests/src/GC/Scenarios/ServerModel/servermodel.cs
new file mode 100644 (file)
index 0000000..45d8ec4
--- /dev/null
@@ -0,0 +1,81 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+//TBD: memory load (external or in process?) 
+//     multiple threads
+
+using System;
+
+namespace ServerSimulator
+{
+
+    /// <summary>
+    /// This is modeled after a server executing requests
+    /// which pin some of their newly allocated objects. 
+    /// </summary>
+    internal static class ServerSimulator
+    {
+
+        internal static Parameters Params;
+        internal static Random Rand;
+
+        // message displayed to user when passed an incorrect parameter or "/?"
+        public static int Usage()
+        {
+            Console.WriteLine();
+            Console.WriteLine("SERVERSIMULATOR: [/randomseed:int] [/numpasses:int]");            
+            Console.WriteLine("\t\t [/cachereplacementrate:float] [/survivalrate:float]");
+            Console.WriteLine("\t\t [/finalizablerate:float] [/allocationvolume:int]");
+            Console.WriteLine("\t\t [/cachesize:int] [/steadystatefactor:int]");
+            Console.WriteLine("\t\t [/numrequests:int] [/staticdatavolume:int]");
+            Console.WriteLine("\t\t [/fifocache:True|False] [/pinning:True|False]");
+            Console.WriteLine();
+            Console.WriteLine("Parameters not passed on the command line are read from the application config file.");
+            return 1;
+        }
+
+        // entrypoint
+        public static int Main(String[] args)
+        {
+            Params = new Parameters();
+
+            if (args.Length > 0)
+            {
+                // check command-line params
+                if (!Params.GetParams(args))
+                {
+                    return Usage();
+                }              
+            }
+
+            int seed = 0;
+            if (Params.RandomSeed != 0)
+            {                
+                // we were passed a random seed
+                seed = Params.RandomSeed;
+            }
+            else
+            {
+                // default to current time
+                seed = (int)DateTime.Now.Ticks;
+            }
+
+            Rand = new Random(seed);
+
+            Console.WriteLine("Using {0} as random seed", seed);
+
+            for (int n = 0; n != Params.NumPasses; n++)
+            {
+                Server server = new Server();
+                server.OnePass();
+                Console.WriteLine("Pass {0} done", n);
+            }
+
+            return 100;
+            
+        }
+    }
+
+}
+
diff --git a/src/coreclr/tests/src/GC/Scenarios/ServerModel/servermodel.csproj b/src/coreclr/tests/src/GC/Scenarios/ServerModel/servermodel.csproj
new file mode 100644 (file)
index 0000000..2df87c3
--- /dev/null
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <CLRTestExecutionArguments>/numrequests:100</CLRTestExecutionArguments>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="Cache.cs" />
+    <Compile Include="Parameters.cs" />
+    <Compile Include="Request.cs" />
+    <Compile Include="Server.cs" />
+    <Compile Include="ServerModel.cs" />
+    <Compile Include="Settings.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/ServerModel/settings.cs b/src/coreclr/tests/src/GC/Scenarios/ServerModel/settings.cs
new file mode 100644 (file)
index 0000000..af950bf
--- /dev/null
@@ -0,0 +1,87 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace ServerSimulator.Properties
+{
+    class Settings {
+
+        public static Settings Default {
+            get {
+                return new Settings();
+            }
+        }
+
+        public int CacheSize {
+            get {
+                return 104857600;
+            }
+        }
+        
+        public float CacheReplacementRate {
+            get {
+                return 0.01f;
+            }
+        }
+        
+        public int NumRequests {
+            get {
+                return 200;
+            }
+        }
+        
+        public int AllocationVolume {
+            get {
+                return 100000;
+            }
+        }
+        
+        public float SurvivalRate {
+            get {
+                return 0.9f;
+            }
+        }
+        
+        public int StaticDataVolume {
+            get {
+                return 500;
+            }
+        }
+        
+        public int SteadyStateFactor {
+            get {
+                return 20;
+            }
+        }
+        
+        public int NumPasses {
+            get {
+                return 1;
+            }
+        }
+        
+        public bool Pinning {
+            get {
+                return false;
+            }
+        }
+        
+        public float FinalizableRate {
+            get {
+                return 0;
+            }
+        }
+        
+        public bool FifoCache {
+            get {
+                return false;
+            }
+        }
+        
+        public int RandomSeed {
+            get {
+                return 0;
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/SingLinkList/app.config b/src/coreclr/tests/src/GC/Scenarios/SingLinkList/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/SingLinkList/singlinkgen.cs b/src/coreclr/tests/src/GC/Scenarios/SingLinkList/singlinkgen.cs
new file mode 100644 (file)
index 0000000..028a1a3
--- /dev/null
@@ -0,0 +1,149 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**************************************************************
+/* a basic test case for GC with cyclic single linked list leaks.
+/* Creat a SingLink object which is a cyclic single linked list
+/* object with iObj number node. then deletes its reference when
+/* the next object is created. Do this loop iRep times.
+/**************************************************************/
+
+
+namespace SingLink {
+    using System;
+
+    public class SingLinkGen
+    {
+// disabling unused variable warning
+#pragma warning disable 0414
+        internal SingLink Mv_Sing;
+#pragma warning restore 0414
+
+        public static int Main(System.String [] Args)
+        {
+            int iRep = 0;
+            int iObj = 0;
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+            switch( Args.Length )
+            {
+               case 1:
+                   if (!Int32.TryParse( Args[0], out iRep ))
+                   {
+                       iRep = 100;
+                   }
+               break;
+               case 2:
+                   if (!Int32.TryParse( Args[0], out iRep ))
+                   {
+                       iRep = 100;
+                   }
+                   if (!Int32.TryParse( Args[1], out iObj ))
+                   {
+                       iObj = 10;
+                   }
+               break;
+               default:
+                   iRep = 100;
+                   iObj = 10;
+               break;
+            }
+
+            SingLinkGen Mv_Leak = new SingLinkGen();
+
+            if(Mv_Leak.runTest(iRep, iObj ))
+            {
+                Console.WriteLine( "Test Passed" );
+                return 100;
+            }
+            else
+            {
+                Console.WriteLine( "Test Failed" );
+                return 1;
+            }
+        }
+
+
+        public bool runTest(int iRep, int iObj)
+        {
+            int retVal = SetLink(iRep, iObj);
+
+            Console.Write("Times ~LinkNode() was called: ");
+            Console.WriteLine(retVal);
+            return ( retVal == iRep*iObj);
+        }
+
+
+        public int SetLink(int iRep, int iObj)
+        {
+            for(int i=0; i<iRep; i++)
+            {
+                Mv_Sing = new SingLink(iObj);
+                //Console.WriteLine("after number {0} singlink is set: {1}", i, GC.GetTotalMemory(false) );
+
+                Mv_Sing = null;
+                GC.Collect();
+                GC.WaitForPendingFinalizers();
+
+            }
+            //Console.WriteLine("total allocated memory: {0}", GC.GetTotalMemory(false));
+
+            return LinkNode.FinalCount;
+
+        }
+
+    }
+
+    public class LinkNode
+    {
+        // disabling unused variable warning
+#pragma warning disable 0414
+        internal LinkNode Last;
+        internal int[] Size;
+#pragma warning restore 0414
+
+        public static int FinalCount = 0;
+
+        ~LinkNode()
+        {
+            FinalCount++;
+        }
+
+        public LinkNode(int SizeNum, LinkNode LastObject)
+        {
+            Last = LastObject;
+            Size = new int[SizeNum * 1024];
+        }
+    }
+
+    public class SingLink
+    {
+        internal LinkNode[] Mv_SLink;
+
+        public SingLink(int Num)
+        {
+            Mv_SLink = new LinkNode[Num];
+
+            if (Num == 0)
+            {
+                return;
+            }
+
+            if (Num == 1)
+            {
+                Mv_SLink[0] = new LinkNode(1, Mv_SLink[0]);
+            }
+            else
+            {
+                Mv_SLink[0] = new LinkNode(1, Mv_SLink[Num - 1]);
+            }
+
+            for (int i = 1; i < Num - 1; i++)
+            {
+                Mv_SLink[i] = new LinkNode((i + 1), Mv_SLink[i - 1]);
+            }
+
+            Mv_SLink[Num - 1] = new LinkNode(Num, Mv_SLink[0]);
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/SingLinkList/singlinkgen.csproj b/src/coreclr/tests/src/GC/Scenarios/SingLinkList/singlinkgen.csproj
new file mode 100644 (file)
index 0000000..1e5a48f
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="SingLinkGen.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/SingLinkList/singlinkstay.cs b/src/coreclr/tests/src/GC/Scenarios/SingLinkList/singlinkstay.cs
new file mode 100644 (file)
index 0000000..e624af9
--- /dev/null
@@ -0,0 +1,150 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/******************************************************************
+/*Test case for testing GC with cyclic single linked list leaks
+/*In every loop. SetLink() to create a SingLink object array whose size
+/*is iRep,  each SingLink Object is a iObj node cyclic single
+/*linked list. MakeLeak() deletes all the object reference in the array
+/*to make all the cyclic single linked lists become memory leaks.
+/******************************************************************/
+
+namespace SingLink {
+    using System;
+
+    public class SingLinkStay
+    {
+
+        internal SingLink []Mv_Sing;
+
+        public static int Main(System.String [] Args)
+        {
+            int iRep = 0;
+            int iObj = 0;
+
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+            switch( Args.Length )
+            {
+               case 1:
+                   if (!Int32.TryParse( Args[0], out iRep ))
+                   {
+                       iRep = 100;
+                   }
+               break;
+               case 2:
+                   if (!Int32.TryParse( Args[0], out iRep ))
+                   {
+                       iRep = 100;
+                   }
+                   if (!Int32.TryParse( Args[1], out iObj ))
+                   {
+                       iObj = 10;
+                   }
+               break;
+               default:
+                   iRep = 100;
+                   iObj = 10;
+               break;
+            }
+
+            SingLinkStay Mv_Leak = new SingLinkStay();
+            if(Mv_Leak.runTest(iRep, iObj ))
+            {
+                Console.WriteLine( "Test Passed" );
+                return 100;
+            }
+            else
+            {
+                Console.WriteLine( "Test Failed" );
+                return 1;
+            }
+
+        }
+
+
+        public bool runTest(int iRep, int iObj)
+        {
+            for(int i=0; i<20; i++)
+            {
+                SetLink(iRep, iObj);
+                MakeLeak(iRep);
+            }
+            return true;
+        }
+
+
+        public void SetLink(int iRep, int iObj)
+        {
+
+            Mv_Sing = new SingLink[iRep];
+            for(int i=0; i<iRep; i++)
+            {
+                Mv_Sing[i] = new SingLink(iObj);
+            }
+        }
+
+
+        public void MakeLeak(int iRep)
+        {
+            for(int i=0; i<iRep; i++)
+            {
+                Mv_Sing[i] = null;
+            }
+        }
+
+    }
+
+    public class LinkNode
+    {
+        // disabling unused variable warning
+#pragma warning disable 0414
+        internal LinkNode Last;
+        internal int[] Size;
+#pragma warning restore 0414
+
+        public static int FinalCount = 0;
+
+        ~LinkNode()
+        {
+            FinalCount++;
+        }
+
+        public LinkNode(int SizeNum, LinkNode LastObject)
+        {
+            Last = LastObject;
+            Size = new int[SizeNum * 1024];
+        }
+    }
+
+    public class SingLink
+    {
+        internal LinkNode[] Mv_SLink;
+
+        public SingLink(int Num)
+        {
+            Mv_SLink = new LinkNode[Num];
+
+            if (Num == 0)
+            {
+                return;
+            }
+
+            if (Num == 1)
+            {
+                Mv_SLink[0] = new LinkNode(1, Mv_SLink[0]);
+            }
+            else
+            {
+                Mv_SLink[0] = new LinkNode(1, Mv_SLink[Num - 1]);
+            }
+
+            for (int i = 1; i < Num - 1; i++)
+            {
+                Mv_SLink[i] = new LinkNode((i + 1), Mv_SLink[i - 1]);
+            }
+
+            Mv_SLink[Num - 1] = new LinkNode(Num, Mv_SLink[0]);
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/SingLinkList/singlinkstay.csproj b/src/coreclr/tests/src/GC/Scenarios/SingLinkList/singlinkstay.csproj
new file mode 100644 (file)
index 0000000..72dd2df
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="SingLinkStay.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/StringCreator/app.config b/src/coreclr/tests/src/GC/Scenarios/StringCreator/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/StringCreator/stringcreator.cs b/src/coreclr/tests/src/GC/Scenarios/StringCreator/stringcreator.cs
new file mode 100644 (file)
index 0000000..5bc065e
--- /dev/null
@@ -0,0 +1,103 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace DefaultNamespace {
+    using System;
+
+    public class StringCreator
+    {
+        internal String m_String;
+        internal String[] m_aString, m_aString1;
+        internal const int MAX_LENGTH = 2000;
+
+        public static int Main(String [] Args)
+        {
+            int iNofObjects = 0;
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            if (Args.Length==1)
+            {
+                if (!Int32.TryParse( Args[0], out iNofObjects ))
+                {
+                    iNofObjects = 2;
+                }
+            }
+            else
+            {
+                iNofObjects = 2;
+            }
+
+
+            RunTest(iNofObjects);
+
+            return 100;
+        }
+
+        public static void RunTest(int iNofObjects)
+        {
+            for (int i = 0; i < iNofObjects; i++)
+            {
+                StringCreator sc = new StringCreator();
+                int slicer = 0;
+                String str;
+                sc.CreateString();
+                do
+                {
+                    slicer = sc.SplitString(slicer);
+                    str = sc.RotateStrings();
+                } while(String.Compare(String.Empty, "") != 0);
+
+                Console.WriteLine("\nslicer = {0}", slicer);
+            }
+        }
+
+        public void CreateString()
+        {
+            m_String = String.Empty;
+            Console.WriteLine("Creating Strings..");
+            for (int i = 0; i < MAX_LENGTH; i++)
+            {
+                if ( i%100 == 0)
+                {
+                    Console.WriteLine("Created Strings: {0} : {1}", i, GC.GetTotalMemory(false));
+                }
+                m_String =  m_String + Convert.ToString(i);
+            }
+        }
+
+
+        public int SplitString(int slicer)
+        {
+            char [] Sep = new char[1];
+            Sep[0] = (slicer.ToString())[0];
+            m_aString = m_String.Split(Sep);
+            slicer += 1;
+            if( slicer >= 10 )
+            {
+                slicer -=10;
+            }
+            return slicer;
+        }
+
+
+        public String RotateStrings()
+        {
+            m_String = String.Empty;
+            m_aString1 = new String[m_aString.Length];
+            Console.WriteLine("Creating More Strings..");
+            for (int i = 0; i < m_aString.Length; i++)
+            {
+                if (i%100 == 0)
+                {
+                    Console.WriteLine("Created Strings: {0} : {1}", i, GC.GetTotalMemory(false));
+                }
+                m_aString1[i] = (m_aString[(m_aString.Length - 1) - i]);
+                m_String = m_String + m_aString[i];
+                m_aString1[i] = m_aString1[i % m_aString.Length] + m_aString1[i % m_aString.Length];
+            }
+
+            return m_String;
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/StringCreator/stringcreator.csproj b/src/coreclr/tests/src/GC/Scenarios/StringCreator/stringcreator.csproj
new file mode 100644 (file)
index 0000000..6c2e49c
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="StringCreator.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/THDChaos/app.config b/src/coreclr/tests/src/GC/Scenarios/THDChaos/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/THDChaos/livingobject.cs b/src/coreclr/tests/src/GC/Scenarios/THDChaos/livingobject.cs
new file mode 100644 (file)
index 0000000..39338db
--- /dev/null
@@ -0,0 +1,67 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace DefaultNamespace {
+    using System.Threading;
+    using System;
+    using System.IO;
+
+    public class LivingObject
+    {
+
+        internal byte [ ]GlobalContainer;
+        internal bool Switch = true;
+        internal static int iCounter = 0;
+
+        public LivingObject( )
+        {
+            Thread Mv_Thread = new Thread( new ThreadStart(this.ThreadStart) );
+            Mv_Thread.Start( );
+        }
+
+
+        public void ThreadStart( )
+        {
+            // console synchronization Console.SetOut(TextWriter.Synchronized(Console.Out));
+
+            if( iCounter%100 == 0)
+            {
+                Console.Out.WriteLine( iCounter + " number of threads has been started" );
+            }
+
+            byte [ ]MethodContainer = new byte[ 1024 ]; // 1K
+
+            if( Switch )
+            {
+                GlobalContainer = new byte[ 1024 ]; // 1K
+            }
+            Switch = !Switch;
+
+            GlobalContainer[ 0 ] = ( byte ) 1;
+            GlobalContainer[ GlobalContainer.Length - 1 ] = ( byte ) 1;
+
+            MethodContainer[ 0 ] = ( byte ) 1;
+            MethodContainer[ MethodContainer.Length - 1 ] = ( byte ) 1;
+
+            IncreatCount( );
+
+            if( LivingObject.iCounter < ThdChaos.iThrd )
+            {
+                Thread Mv_Thread = new Thread( new ThreadStart (this.ThreadStart) );
+                Mv_Thread.Start( );
+            }
+
+        }
+
+
+        public void IncreatCount()
+        {
+            lock(this)
+            {
+                iCounter += 1;
+            }
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/THDChaos/masterthread.cs b/src/coreclr/tests/src/GC/Scenarios/THDChaos/masterthread.cs
new file mode 100644 (file)
index 0000000..0486d49
--- /dev/null
@@ -0,0 +1,44 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace DefaultNamespace {
+    using System;
+    using System.IO;
+
+    public class MasterThread
+    {
+        internal int iNum = 0;
+
+        public MasterThread( int Children )
+        {
+            // console synchronization Console.SetOut(TextWriter.Synchronized(Console.Out));
+            iNum = Children;
+            runTest();
+        }
+
+        public void runTest()
+        {
+
+            LivingObject [ ]Mv_LivingObject = new LivingObject[ 25 ];
+            int iTotal = Mv_LivingObject.Length;
+            for ( int i = 0; i < iNum; i++ )
+            {
+                for ( int j = 0; j < iTotal; j++ )
+                {
+                    Console.Out.WriteLine( "{0} Object Created", j );
+                    Console.Out.WriteLine();
+
+                    Mv_LivingObject[ j ] = new LivingObject( );
+                }
+
+                Console.Out.WriteLine( "+++++++++++++++++++++++++++++++++++Nest {0} of {1}", i, iNum );
+                Console.Out.WriteLine();
+            }
+
+            Console.Out.WriteLine( "******************************* FinalRest" );
+        }
+
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/THDChaos/thdchaos.cs b/src/coreclr/tests/src/GC/Scenarios/THDChaos/thdchaos.cs
new file mode 100644 (file)
index 0000000..ec8d068
--- /dev/null
@@ -0,0 +1,44 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+
+//======================================================
+//
+//  ThdChaos -- caues multiple asserts
+//
+//======================================================
+
+namespace DefaultNamespace {
+    using System.Threading;
+    using System;
+    using System.IO;
+
+    public class ThdChaos
+    {
+        internal static int iThrd = 0;
+        public static int Main( System.String [] Args )
+        {
+            Console.Out.WriteLine("Test should return with ExitCode 100 ...");
+            // console synchronization Console.SetOut(TextWriter.Synchronized(Console.Out));
+            Console.Out.WriteLine("Args.Length="+Args.Length );
+            if(Args.Length >=1 )
+            {
+                if (!Int32.TryParse( Args[0], out iThrd ))
+                {
+                    iThrd = 20;
+                }
+            }
+            else
+            {
+                iThrd = 20;
+            }
+
+            ThdChaos Mv_ThdChaos = new ThdChaos();
+            MasterThread Mv_Thread = new MasterThread( iThrd );
+            return 100;
+
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/THDChaos/thdchaos.csproj b/src/coreclr/tests/src/GC/Scenarios/THDChaos/thdchaos.csproj
new file mode 100644 (file)
index 0000000..96de3a3
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="MasterThread.cs" />
+    <Compile Include="ThdChaos.cs" />
+    <Compile Include="LivingObject.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/THDList/app.config b/src/coreclr/tests/src/GC/Scenarios/THDList/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/THDList/linkedlist.cs b/src/coreclr/tests/src/GC/Scenarios/THDList/linkedlist.cs
new file mode 100644 (file)
index 0000000..02321fa
--- /dev/null
@@ -0,0 +1,91 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace ThdList {
+    using System.Threading;
+    using System;
+    using System.IO;
+
+    public class Node
+    {
+        internal int m_data;
+        internal Node m_pNext;
+    }
+
+
+    public class LinkedList
+    {
+
+        internal Node m_pHead;
+        internal Random m_Random;
+
+        public LinkedList(int ThreadId)
+        {
+            m_pHead = null;
+            m_Random = new Random();
+            // console synchronization Console.SetOut(TextWriter.Synchronized(Console.Out));
+        }
+
+        public void Empty (int ThreadId)
+        {
+            Console.WriteLine("Thread {0}: List Empty", ThreadId);
+            m_pHead = null;
+        }
+
+        public void AddNodes (int howMany, int ThreadId)
+        {
+            //Adds howMany nodes to the linked list
+            for (int i = 0; i < howMany; i++)
+            {
+                m_pHead = Insert(m_pHead, m_Random.Next(10));
+            }
+            Console.WriteLine("Thread {0} Added {1} Nodes", ThreadId, howMany);
+        }
+
+        public void DeleteNodes (int howMany, int ThreadId)
+        {
+            //Deletes howMany nodes from the linked list
+            for (int i = 0; i < howMany; i++)
+            {
+                m_pHead = Delete(m_pHead, m_Random.Next(10));
+            }
+            Console.WriteLine("Thread {0} Deleted {1} Nodes", ThreadId, howMany);
+        }
+
+        private Node Insert(Node head, int element)
+        {
+
+            if(head == null)                                            //if is NULL make a new node
+            {                                                           //and copy number to the new node
+                head=new Node();                                        //make new node
+                head.m_data = element;                                  //copy number
+                head.m_pNext=null ;                                     //set the next to NULL
+            }
+            else
+            {
+                Node temp;
+                temp = new Node();                                      //Add the new node as the head
+                temp.m_data = element;
+                temp.m_pNext = head;
+                head = temp;
+            }
+            return head;
+        }
+
+
+        private Node Delete(Node head, int element)
+        {
+            if(head == null)
+            {
+                return head;                                                //Node not found
+            }
+            if (element == head.m_data)                                 //if it was the first data (node)
+            {
+                return head.m_pNext;
+            }
+            head.m_pNext = Delete(head.m_pNext, element);               //Recurse to the next element
+            return head;                                                // in the list
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/THDList/llthread.cs b/src/coreclr/tests/src/GC/Scenarios/THDList/llthread.cs
new file mode 100644 (file)
index 0000000..426793e
--- /dev/null
@@ -0,0 +1,47 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace ThdList {
+    using System.Threading;
+    using System;
+    using System.IO;
+
+    public class LLThread {
+
+        internal int [] mA_Count = {10000, -5000, -15000, 3000, -6000, 0, 15000, 0, 10000,0,100,100}; //Action Array +ve add, -ve delete, 0 empty
+        internal int m_id = 0;
+        internal LinkedList m_LinkedList;
+        internal Thread Mv_Thread;
+
+        public LLThread(int ThreadId)
+        {
+            // console synchronization Console.SetOut(TextWriter.Synchronized(Console.Out));
+            m_LinkedList = new LinkedList(ThreadId);
+            m_id = ThreadId;
+            Mv_Thread = new Thread( new ThreadStart (this.ThreadStart) );
+            Mv_Thread.Start( );
+            Console.Out.WriteLine("Started Thread: " + m_id);
+        }
+
+        public void ThreadStart()
+        {
+            for (int i = 0; i < mA_Count.Length; i++)
+            {
+                if (mA_Count[i] == 0)
+                {
+                    m_LinkedList.Empty(m_id);
+                }
+                else if (mA_Count[i] > 0 )
+                {
+                    m_LinkedList.AddNodes(mA_Count[i], m_id);
+                }
+                else
+                {
+                    m_LinkedList.DeleteNodes((mA_Count[i] * -1), m_id);
+                }
+            }
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/THDList/thdlist.cs b/src/coreclr/tests/src/GC/Scenarios/THDList/thdlist.cs
new file mode 100644 (file)
index 0000000..f97f369
--- /dev/null
@@ -0,0 +1,53 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/**
+ * Description:
+ *      Mainly stresses the GC by creating n threads each manipulating its own local Linked List.
+ *      Each thread in turn adds and deletes thousands of nodes from the linked list.
+ */
+
+
+namespace ThdList {
+    using System.Threading;
+    using System;
+    using System.IO;
+
+    public class ThdList
+    {
+
+        public static int Main (System.String[] Args)
+        {
+
+            Console.Out.WriteLine("Test should return with ExitCode 100 ...");
+            // console synchronization Console.SetOut(TextWriter.Synchronized(Console.Out));
+
+            int iNofThread = 0;
+
+            if (Args.Length == 1)
+            {
+                if (!Int32.TryParse( Args[0], out iNofThread ))
+                {
+                    iNofThread = 2;
+                }
+            }
+            else
+            {
+                iNofThread = 2;
+            }
+
+
+            LLThread Mv_LLThread;
+
+            //Creates m_iNofThreads LLThread objects
+            //Each LLThread then launches a thread in its constructor
+            for (int i = 0; i < iNofThread; i++)
+            {
+                Mv_LLThread = new LLThread(i);
+            }
+            return 100;
+        }
+
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/THDList/thdlist.csproj b/src/coreclr/tests/src/GC/Scenarios/THDList/thdlist.csproj
new file mode 100644 (file)
index 0000000..92d87e1
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="ThdList.cs" />
+    <Compile Include="LLThread.cs" />
+    <Compile Include="LinkedList.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/WeakReference/app.config b/src/coreclr/tests/src/GC/Scenarios/WeakReference/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/WeakReference/getgencollect.cs b/src/coreclr/tests/src/GC/Scenarios/WeakReference/getgencollect.cs
new file mode 100644 (file)
index 0000000..0fd7e24
--- /dev/null
@@ -0,0 +1,81 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/******************************************************************************/
+/* test: GetGenCollect
+/* Purpose: Test GC.GetGeneration(Object/WeakRefernce) and GC.Collect( Gen )
+/* How: 1.GC.Collect( gen ) should collect the object in "gen" generation.
+/*  2.in Object mv_obj's finalize, the return value of GetGeneration(this)
+/*  should be same with GetGeneration(wf);
+/******************************************************************************/
+
+namespace DefaultNamespace {
+    using System;
+
+    internal class GetGenCollect
+    {
+        internal int Gen;
+        internal static WeakReference wf;
+        internal static bool retVal;
+        public static int Main( String [] str )
+        {
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            GetGenCollect mv_obj = new GetGenCollect();
+            wf = new WeakReference( mv_obj, true );
+            mv_obj.MakeGCBusy();
+            mv_obj.Gen = GC.GetGeneration( mv_obj );
+            int g = mv_obj.Gen;
+            mv_obj = null;
+
+            GC.Collect( g );
+            GC.WaitForPendingFinalizers();
+            GC.Collect( g );
+
+            if (retVal)
+            {
+                Console.WriteLine ("Test Passed" );
+                return 100;
+            }
+            Console.WriteLine ("Test Failed" );
+            return 1;
+
+        }
+
+
+        ~GetGenCollect()
+        {
+            Console.WriteLine( "Verified that the object in generation {0} is finalized by calling GC.Collect({0}).",Gen);
+            int g = GC.GetGeneration( this );
+
+            int gwf = GC.GetGeneration( GetGenCollect.wf );
+            Console.WriteLine( "g={0}, gwf={1}", g, gwf );
+
+            if( g != gwf )
+            {
+                Console.WriteLine( "GetGeneration( WeakReferance ) may have problem!" );
+                retVal = false;
+                return;
+            }
+
+            Console.WriteLine( "Passed " );
+            retVal = true;
+
+        }
+
+        public void MakeGCBusy()
+        {
+            Object [] vary = new Object[2];
+            for( int i=0; i< 1000; i++ )
+            {
+                vary[0] = (new int[i]);
+                vary[1] = ( vary[0] );
+                if( i%20 == 0 )
+                {
+                    GC.Collect();
+                }
+            }
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/WeakReference/getgencollect.csproj b/src/coreclr/tests/src/GC/Scenarios/WeakReference/getgencollect.csproj
new file mode 100644 (file)
index 0000000..8bf2b81
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="GetGenCollect.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/WeakReference/weakref.cs b/src/coreclr/tests/src/GC/Scenarios/WeakReference/weakref.cs
new file mode 100644 (file)
index 0000000..db1e9b8
--- /dev/null
@@ -0,0 +1,165 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace DefaultNamespace {
+    using System;
+    using System.Collections.Generic;
+
+    internal class CreateObj
+    {
+        private String [] Str;
+        private List<WeakReference> alWeakRef;
+
+        public CreateObj(int iObj,int iSwitch)
+        {
+            Str = new String[iObj];
+            alWeakRef = new List<WeakReference>();
+        }
+
+        public bool RunTest(int iObj,int iSwitch)
+        {
+            if (!DeleteObj(iObj,iSwitch))
+            {
+                return false;
+            }
+            return CheckResult(iObj);
+        }
+
+         public bool DeleteObj(int iObj,int iSwitch)
+         {
+            for( int i= 0; i< iObj; i++ )
+            {
+                Str[i] = ( i.ToString() );
+                alWeakRef.Add( new WeakReference( Str[i], iSwitch==1) );
+            }
+
+            GC.Collect();
+
+            for( int i=0; i< iObj; i++)
+            {
+                if ( alWeakRef[i].Target == null )
+                {
+                    //*all weakref have strong reference, so it should not return null
+                    return false;
+                }
+            }
+
+            for( int i=0; i< iObj; i++)
+            {
+                Str[i] = null;
+            }
+            GC.Collect();
+
+            return true;
+
+          }
+
+          public bool CheckResult(int iObj)
+          {
+            for( int i=0; i< iObj; i++)
+            {
+                if ( alWeakRef[ i ].Target != null )
+                {
+                    //*no weakref have strong reference, so it should return null
+                    return false;
+                }
+            }
+            return true;
+          }
+
+    }
+
+
+    internal class CreateObj2
+    {
+        public  WeakRef mv_Obj;
+
+        public CreateObj2()
+        {
+            mv_Obj = new WeakRef();
+        }
+
+        public bool RunTest(int iObj,int iSwitch)
+        {
+            return ( mv_Obj.RealWeakRef( iObj, iSwitch ));
+        }
+    }
+
+
+    internal class WeakRef
+    {
+
+        public bool RealWeakRef(int iObj, int iSwitch)
+        {
+
+            CreateObj temp = new CreateObj(iObj,iSwitch);
+            bool result = temp.RunTest(iObj,iSwitch);
+            return result;
+        }
+    }
+
+
+    internal class Test
+    {
+        public static int Main(String [] Args)
+        {
+            int iObj = 0;
+            int iSwitch = 0;
+
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            if (Args.Length >=2)
+            {
+                if (!Int32.TryParse( Args[0], out iObj ))
+                {
+                    iObj = 10;
+                }
+                if (!Int32.TryParse( Args[1], out iSwitch ))
+                {
+                    iSwitch = 1;
+                }
+            }
+            else
+            {
+                iObj = 10;
+                iSwitch = 1;
+            }
+
+
+            CreateObj2 temp = new CreateObj2();
+            if (temp.RunTest(iObj,iSwitch))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            Console.WriteLine("Test Failed");
+            return 1;
+        }
+
+    }
+
+    internal class BNode
+    {
+        public static int icCreateNode = 0;
+        public static int icFinalNode = 0;
+        internal int [] mem;
+        internal List<BNode> ResObj = new List<BNode>();
+        public BNode( int i )
+        {
+            icCreateNode++;
+            mem = new int[i];
+            mem[0] = 0;
+            if(i > 1 )
+            {
+                mem[mem.Length-1] = mem.Length-1;
+            }
+        }
+
+        ~BNode()
+        {
+            icFinalNode++;
+            ResObj.Add( this );
+        }
+    }
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/WeakReference/weakref.csproj b/src/coreclr/tests/src/GC/Scenarios/WeakReference/weakref.csproj
new file mode 100644 (file)
index 0000000..b93fb3c
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="WeakRef.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/WeakReference/weakreffinal.cs b/src/coreclr/tests/src/GC/Scenarios/WeakReference/weakreffinal.cs
new file mode 100644 (file)
index 0000000..a356cec
--- /dev/null
@@ -0,0 +1,182 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace DefaultNamespace {
+    using System;
+    using System.Collections.Generic;
+
+    internal class CreateObj
+    {
+        public BNode []rgNode;
+        public List<WeakReference> alWeakRef;
+        public bool bret;
+
+        public CreateObj(int iObj)
+        {
+            rgNode = new BNode[iObj];
+            alWeakRef = new List<WeakReference>();
+            bret = true;
+        }
+
+        public bool RunTest(int iObj,int iSwitch)
+        {
+            DeleteObj(iObj,iSwitch);
+            bool result = CheckResult(iObj,iSwitch);
+            return result;
+        }
+
+        public void DeleteObj(int iObj,int iSwitch)
+        {
+            for( int i= 0; i< iObj; i++ )
+            {
+                rgNode[i] = new BNode( i+1 );
+                alWeakRef.Add( new WeakReference( rgNode[i], (iSwitch == 1) ) );
+            }
+
+            GC.Collect();
+            for( int i=0; i< iObj; i++)
+            {
+                if ( (alWeakRef[ i ]).Target == null )
+                {
+                    //*all weakref have strong reference, so it should not return null
+                    bret = false;
+                }
+            }
+
+            for( int i=0; i< iObj; i++)
+            {
+                rgNode[i] = null;
+            }
+
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
+
+        }
+
+        public bool CheckResult(int iObj,int iSwitch)
+        {
+            for( int i=0; i< iObj; i++)
+            {
+                if(iSwitch == 1)
+                {
+                    if ( (alWeakRef[ i ]).Target  == null )
+                    {
+                        //*weakrefs have strong reference, so it should not return null
+                        bret = false;
+                    }
+                }
+                else
+                {
+                    if ( (alWeakRef[ i ]).Target  != null )
+                    {
+                        //*no weakref have strong reference, so it should return null
+                        bret = false;
+                    }
+                }
+            }
+            for(int i=0; i< iObj; i++ )
+            {
+                rgNode[i] = (BNode)BNode.ResObj[ i ];
+            }
+            return bret;
+        }
+
+    }
+
+    internal class WeakRefFinal
+    {
+
+        public bool RealWeakRef(int iObj, int iSwitch)
+        {
+            CreateObj temp = new CreateObj(iObj);
+            bool result = temp.RunTest(iObj,iSwitch);
+            return result;
+        }
+    }
+
+
+    internal class BNode
+    {
+        public static int icCreateNode = 0;
+        public static int icFinalNode = 0;
+        internal int [] mem;
+        public static List<BNode> ResObj = new List<BNode>();
+        public BNode( int i )
+        {
+            icCreateNode++;
+            mem = new int[i];
+            mem[0] = 0;
+            if(i > 1 )
+            {
+                mem[mem.Length-1] = mem.Length-1;
+            }
+
+        }
+
+    ~BNode()
+        {
+            icFinalNode++;
+            ResObj.Add( this );
+        }
+    }
+
+    internal class CreateObj2
+    {
+        public WeakRefFinal mv_Obj;
+
+        public CreateObj2()
+        {
+            mv_Obj = new WeakRefFinal();
+        }
+
+        public bool RunTest(int iObj,int iSwitch)
+        {
+            return ( mv_Obj.RealWeakRef( iObj, iSwitch ));
+        }
+
+   }
+
+    internal class Test
+    {
+        public static int Main(String [] Args)
+        {
+            int iObj = 0;
+            int iSwitch = 0;
+
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            if (Args.Length >=2)
+            {
+                if (!Int32.TryParse( Args[0], out iObj ))
+                {
+                    iObj = 10;
+                }
+                if (!Int32.TryParse( Args[1], out iSwitch ))
+                {
+                    iSwitch = 1;
+                }
+            }
+            else
+            {
+                iObj = 10;
+                iSwitch = 1;
+            }
+
+            CreateObj2 temp = new CreateObj2();
+            if (temp.RunTest(iObj,iSwitch))
+            {
+                Console.WriteLine("Test Passed");
+                return 100;
+            }
+            Console.WriteLine("Test Failed");
+            return 1;
+
+
+
+        }
+
+   }
+
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/WeakReference/weakreffinal.csproj b/src/coreclr/tests/src/GC/Scenarios/WeakReference/weakreffinal.csproj
new file mode 100644 (file)
index 0000000..6fca7a9
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="WeakRefFinal.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/Scenarios/muldimjagary/app.config b/src/coreclr/tests/src/GC/Scenarios/muldimjagary/app.config
new file mode 100644 (file)
index 0000000..c51f616
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.20.0" newVersion="4.0.20.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Text.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Globalization" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>
diff --git a/src/coreclr/tests/src/GC/Scenarios/muldimjagary/muldimjagary.cs b/src/coreclr/tests/src/GC/Scenarios/muldimjagary/muldimjagary.cs
new file mode 100644 (file)
index 0000000..eddea85
--- /dev/null
@@ -0,0 +1,181 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace DefaultNamespace {
+using System;
+
+/*************************************************************/
+/* test: MulDimJagAry.cs
+/* Purpose: Test GC with Multiple dimentions array
+/* Coverage: int[][], Object[][], Object[][][], Variant[][][],
+/*           take Mul_Dimention array as function argument.
+/*************************************************************/
+
+
+    class MulDimJagAry
+    {
+        public static int Main(String []args)
+        {
+            int iDim1 = 100;
+            int iDim2 = 100;
+            int iRep = 30;
+            Console.WriteLine("Test should return with ExitCode 100 ...");
+
+            MulDimJagAry mv_Obj = new MulDimJagAry();
+
+            int [][] iJag;
+            for(int j=0; j<iRep; j++ )
+            {
+                iJag = new int[iDim1][];
+                for( int i=0; i< iDim2; i++ )
+                {
+                    iJag[i] = new int[i];
+                    if( i>= 1 )
+                    {
+                        iJag[i][0] = 0;
+                        iJag[i][i-1] = i;
+                    }
+                }
+                //if( GC.GetTotalMemory(false) >= 1024*1024*6 )
+                //{
+                //    Console.WriteLine( "HeapSize before GC: "+ GC.GetTotalMemory(false) );
+                //    GC.Collect();
+                //    Console.WriteLine( "HeapSize after GC: "+ GC.GetTotalMemory(false) );
+                //}
+            }
+
+            Object[][] oJag;
+            for(int j=0; j<iRep; j++ )
+            {
+                oJag = new Object[iDim1][];
+                for( int i=0; i< iDim1; i++ )
+                {
+                    oJag[i] = new Object[i];
+                    if( i>= 1 )
+                    {
+                        oJag[i][0] = (0);
+                        oJag[i][i-1] = new long[i];
+                    }
+
+                }
+                //if( GC.GetTotalMemory(false) >= 1024*1024*6 )
+                //{
+                //    Console.WriteLine( "HeapSize before GC: "+ GC.GetTotalMemory(false) );
+                //    GC.Collect();
+                //    Console.WriteLine( "HeapSize after GC: "+ GC.GetTotalMemory(false) );
+                //}
+            }
+
+            Object[][][] oJag3 = new Object[iDim1][][];
+            oJag3[3] = new Object[iDim2][];
+            oJag3[4] = new Object[iDim2][];
+            for (int i = 0; i < iDim2; i ++)
+            {
+                oJag3[4][i] = new Object[iDim1];
+            }
+
+            for(int j=0; j<iRep; j++ )
+            {
+                oJag3 = new Object[iDim1][][];
+                for( int i=0; i< iDim1; i++ )
+                {
+                    oJag3[i] = new Object[iDim2][];
+                    for(int k=0; k<iDim2; k++)
+                    {
+                        oJag3[i][k] = new Object[k];
+                        for(int l = 0; l< k; l++ )
+                        {
+                            if( l>= 1 )
+                            {
+                                oJag3[i][k][0] = (0);
+                                oJag3[i][k][l-1] = new long[l];
+                            }
+                        }
+                    }
+
+                }
+                //if( GC.GetTotalMemory(false) >= 1024*1024*6 )
+                //{
+                //    Console.WriteLine( "HeapSize before GC: "+ GC.GetTotalMemory(false) );
+                //    GC.Collect();
+                //    Console.WriteLine( "HeapSize after GC: "+ GC.GetTotalMemory(false) );
+                //}
+            }
+
+            for(int j=0; j<iRep; j++ )
+            {
+                oJag3 = new Object[iDim1][][];
+                mv_Obj.SetThreeDimJagAry( oJag3, iDim1, iDim2 );
+                //if( GC.GetTotalMemory(false) >= 1024*1024*6 )
+                //{
+                //    Console.WriteLine( "HeapSize before GC: "+ GC.GetTotalMemory(false) );
+                //    GC.Collect();
+                //    Console.WriteLine( "HeapSize after GC: "+ GC.GetTotalMemory(false) );
+                //}
+            }
+
+
+            Object[][][] vJag;
+            for(int j=0; j<iRep; j++ )
+            {
+                vJag = new Object[iDim1][][];
+                mv_Obj.SetThreeDimJagVarAry( vJag, iDim1, iDim2 );
+                //if( GC.GetTotalMemory(false) >= 1024*1024*6 )
+                //{
+                //    Console.WriteLine( "HeapSize before GC: "+ GC.GetTotalMemory(false) );
+                //    GC.Collect();
+                //    Console.WriteLine( "HeapSize after GC: "+ GC.GetTotalMemory(false) );
+                //}
+            }
+
+
+            return 100;
+
+        }
+
+        public void SetThreeDimJagAry( Object [][][] oJag, int iDim1, int iDim2 )
+        {
+            for( int i=0; i< iDim1; i++ )
+            {
+                oJag[i] = new Object[iDim2][];
+                for(int k=0; k<iDim2; k++)
+                {
+                    oJag[i][k] = new Object[k];
+                    for(int l = 0; l< k; l++ )
+                    {
+                        if( l>= 1 )
+                        {
+                            oJag[i][k][0] = (0);
+                            oJag[i][k][l-1] = new float[l];
+
+                        }
+                    }
+
+                }
+            }
+        }
+
+        public void SetThreeDimJagVarAry( Object [][][] vJag, int iDim1, int iDim2 )
+        {
+            for( int i=0; i< iDim1; i++ )
+            {
+                vJag[i] = new Object[iDim2][];
+                for(int k=0; k<iDim2; k++)
+                {
+                    vJag[i][k] = new Object[k];
+                    for(int l = 0; l< k; l++ )
+                    {
+                        if( l>= 1 )
+                        {
+                            vJag[i][k][0] = (0);
+                            vJag[i][k][l-1] = ( new double[l] );
+                        }
+                    }
+
+                }
+            }
+        }
+    }
+
+}
diff --git a/src/coreclr/tests/src/GC/Scenarios/muldimjagary/muldimjagary.csproj b/src/coreclr/tests/src/GC/Scenarios/muldimjagary/muldimjagary.csproj
new file mode 100644 (file)
index 0000000..ecb0bea
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <!-- Add Compile Object Here -->
+    <Compile Include="MulDimJagAry.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+    <None Include="$(GCPackagesConfigFileDirectory)extra\project.json" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(GCPackagesConfigFileDirectory)extra\project.json</ProjectJson>
+    <ProjectLockJson>$(GCPackagesConfigFileDirectory)extra\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
\ No newline at end of file
     "System.Xml.ReaderWriter": "4.0.11-beta-23302",
     "System.Xml.XDocument": "4.0.11-beta-23302",
     "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
+    "System.Xml.XmlSerializer": "4.0.11-beta-23302",
+    "System.Threading.Thread": "4.0.0-beta-23302"
   },
   "frameworks": {
     "dnxcore50": {}
   }
-}
+}
\ No newline at end of file
@@ -26,9 +26,9 @@
     "System.Xml.ReaderWriter": "4.0.11-beta-23302",
     "System.Xml.XDocument": "4.0.11-beta-23302",
     "System.Xml.XmlDocument": "4.0.1-beta-23302",
-    "System.Xml.XmlSerializer": "4.0.11-beta-23302"
+    "System.Xml.XmlSerializer": "4.0.11-beta-23302",
   },
   "frameworks": {
     "dnxcore50": {}
   }
-}
+}
\ No newline at end of file
diff --git a/src/coreclr/tests/src/GC/dir.props b/src/coreclr/tests/src/GC/dir.props
new file mode 100644 (file)
index 0000000..4e8400f
--- /dev/null
@@ -0,0 +1,7 @@
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="..\dir.props" />
+
+  <PropertyGroup>
+    <GCPackagesConfigFileDirectory>$(MSBuildThisFileDirectory)config\</GCPackagesConfigFileDirectory>
+  </PropertyGroup>
+</Project>
\ No newline at end of file
index c38e893..1c376db 100644 (file)
@@ -174,4 +174,37 @@ JIT/Regression/Dev11/External/dev11_145295/CSharpPart/CSharpPart.sh
 Interop/ArrayMarshalling/ByValArray/MarshalArrayByValTest/MarshalArrayByValTest.sh
 Interop/StringMarshalling/LPSTR/LPSTRTest/LPSTRTest.sh
 Interop/StringMarshalling/LPTSTR/LPTSTRTest/LPTSTRTest.sh
-
+GC/API/WeakReference/Finalize2/Finalize2.sh
+GC/API/WeakReference/NullHandle/NullHandle.sh
+GC/API/WeakReference/Target/Target.sh
+GC/API/WeakReference/IsAlive/IsAlive.sh
+GC/API/WeakReference/IsAlive_neg/IsAlive_neg.sh
+GC/Features/Finalizer/finalizeother/finalizedirectedgraph/finalizedirectedgraph.sh
+GC/LargeMemory/Allocation/finalizertest/finalizertest.sh
+GC/LargeMemory/API/gc/reregisterforfinalize/reregisterforfinalize.sh
+GC/LargeMemory/API/gc/collect/collect.sh
+GC/Scenarios/DoublinkList/doublinknoleak2/doublinknoleak2.sh
+GC/Scenarios/DoublinkList/doublinknoleak/doublinknoleak.sh
+GC/Scenarios/LeakWheel/leakwheel/leakwheel.sh
+GC/Scenarios/SingLinkList/singlinkgen/singlinkgen.sh
+GC/Scenarios/WeakReference/getgencollect/getgencollect.sh
+GC/Scenarios/WeakReference/weakref/weakref.sh
+GC/LargeMemory/API/gc/getgeneration/getgeneration.sh
+GC/Scenarios/BaseFinal/basefinal/basefinal.sh
+GC/Coverage/concurrentspin2/concurrentspin2.sh
+GC/Coverage/smalloom/smalloom.sh
+GC/Coverage/271010/271010.sh
+GC/Features/BackgroundGC/concurrentspin2/concurrentspin2.sh
+GC/Features/BackgroundGC/foregroundgc/foregroundgc.sh
+GC/Features/LOHCompaction/lohcompact_stress/lohcompact_stress.sh
+GC/Features/LOHCompaction/lohcompactscenariorepro/lohcompactscenariorepro.sh
+GC/Features/LOHCompaction/lohcompactapi2/lohcompactapi2.sh
+GC/Features/LOHFragmentation/lohfragmentation/lohfragmentation.sh
+GC/Features/PartialCompaction/partialcompactiontest/partialcompactiontest.sh
+GC/Features/PartialCompaction/partialcompactionwloh/partialcompactionwloh.sh
+GC/Features/PartialCompaction/eco1/eco1.sh
+GC/Features/SustainedLowLatency/sustainedlowlatency_race_reverse/sustainedlowlatency_race_reverse.sh
+GC/Features/SustainedLowLatency/scenario/scenario.sh
+GC/Features/SustainedLowLatency/sustainedlowlatency_race/sustainedlowlatency_race.sh
+GC/Regressions/dev10bugs/536168/536168/536168.sh
+GC/M10/RefCrossTHDs/refcrossthds/refcrossthds.sh
index 76be20d..d0d4b34 100644 (file)
@@ -189,3 +189,4 @@ JIT/opt/Inline/tests/xmodb/xmodb.sh
 JIT/Regression/CLR-x86-JIT/V1-M12-Beta2/b79250/b79250/b79250.sh
 managed/Compilation/Compilation/Compilation.sh
 Regressions/coreclr/0584/Test584/Test584.sh
+GC/Regressions/v2.0-beta2/437657/437657/437657.sh
index cde4dc8..66c083a 100644 (file)
    <ExcludeList Include="$(XunitTestBinBase)\Interop\StringMarshalling\LPTSTR\LPTSTRTest\LPTSTRTest.cmd">
             <Issue>needs triage</Issue>
         </ExcludeList>
-    </ItemGroup>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\API\WeakReference\Finalize2\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\API\WeakReference\NullHandle\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\API\WeakReference\Target\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\API\WeakReference\IsAlive\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\API\WeakReference\IsAlive_neg\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Features\Finalizer\finalizeother\finalizedirectedgraph\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\LargeMemory\Allocation\finalizertest\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\LargeMemory\Allocation\largeexceptiontest\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\LargeMemory\API\gc\reregisterforfinalize\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\LargeMemory\API\gc\collect\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\LargeMemory\API\gc\suppressfinalize\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\LargeMemory\API\gc\getgeneration\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\LargeMemory\Regressions\largearraytest\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\LargeMemory\API\gc\keepalive\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\LargeMemory\API\gc\gettotalmemory\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\DoublinkList\doublinknoleak2\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\ReflectObj\reflectobj\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\DoublinkList\doublinknoleak\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\LeakWheel\leakwheel\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\SingLinkList\singlinkgen\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\WeakReference\getgencollect\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\WeakReference\weakref\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\BaseFinal\basefinal\*">
+                        <Issue>3391</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Coverage\concurrentspin2\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Coverage\smalloom\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Coverage\271010\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Features\BackgroundGC\concurrentspin2\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Features\BackgroundGC\foregroundgc\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Features\LOHCompaction\lohcompact_stress\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Features\LOHCompaction\lohcompactscenariorepro\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Features\LOHCompaction\lohcompactapi2\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Features\LOHFragmentation\lohfragmentation\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Features\PartialCompaction\partialcompactiontest\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Features\PartialCompaction\partialcompactionwloh\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Features\PartialCompaction\eco1\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Features\SustainedLowLatency\sustainedlowlatency_race_reverse\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Features\SustainedLowLatency\scenario\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Features\SustainedLowLatency\sustainedlowlatency_race\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Regressions\dev10bugs\536168\536168\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+               <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\muldimjagary\muldimjagary\*">
+                        <Issue>3392</Issue>
+               </ExcludeList>
+       </ItemGroup>
 </Project>