Merge pull request #916 from akoeplinger/fix-gac-test
[mono.git] / mcs / class / corlib / System / GC.cs
1 //
2 // System.GC.cs
3 //
4 // Author:
5 //   Paolo Molaro (lupus@ximian.com)
6 //
7 // (C) 2001 Ximian, Inc.  http://www.ximian.com
8 //
9
10 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 using System.Runtime.CompilerServices;
34 using System.Runtime.ConstrainedExecution;
35 using System.Security.Permissions;
36
37 namespace System
38 {
39         public static class GC
40         {
41
42                 public extern static int MaxGeneration {
43                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
44                         get;
45                 }
46
47                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
48                 extern static void InternalCollect (int generation);
49                 
50                 public static void Collect () {
51                         InternalCollect (MaxGeneration);
52                 }
53
54                 public static void Collect (int generation) {
55                         if (generation < 0)
56                                 throw new ArgumentOutOfRangeException ("generation");
57                         InternalCollect (generation);
58                 }
59
60                 [MonoDocumentationNote ("mode parameter ignored")]
61                 public static void Collect (int generation, GCCollectionMode mode) {
62                         Collect (generation);
63                 }
64
65 #if NET_4_5
66                 [MonoDocumentationNote ("mode and blocking parameters ignored")]
67                 public static void Collect (int generation, GCCollectionMode mode, bool blocking) {
68                         Collect (generation);
69                 }
70 #endif
71
72                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
73                 public extern static int GetGeneration (object obj);
74
75                 public static int GetGeneration (WeakReference wo) {
76                         object obj = wo.Target;
77                         if (obj == null)
78                                 throw new ArgumentException ();
79                         return GetGeneration (obj);
80                 }
81
82                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
83                 public extern static long GetTotalMemory (bool forceFullCollection);
84
85                 /* this icall has weird semantics check the docs... */
86                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
87                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
88                 public extern static void KeepAlive (object obj);
89                 
90                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
91                 public extern static void ReRegisterForFinalize (object obj);
92
93                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
94                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
95                 public extern static void SuppressFinalize (object obj);
96
97                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
98                 public extern static void WaitForPendingFinalizers ();
99
100                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
101                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
102                 public extern static int CollectionCount (int generation);
103
104                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
105                 private extern static void RecordPressure (long bytesAllocated);
106
107                 public static void AddMemoryPressure (long bytesAllocated) {
108                         RecordPressure (bytesAllocated);
109                 }
110
111                 public static void RemoveMemoryPressure (long bytesAllocated) {
112                         RecordPressure (-bytesAllocated);
113                 }
114
115 #if NET_4_0
116                 [PermissionSetAttribute (SecurityAction.LinkDemand, Name = "FullTrust")]
117                 [MonoTODO]
118                 public static GCNotificationStatus WaitForFullGCApproach () {
119                         throw new NotImplementedException ();
120                 }
121
122                 [PermissionSetAttribute (SecurityAction.LinkDemand, Name = "FullTrust")]
123                 [MonoTODO]
124                 public static GCNotificationStatus WaitForFullGCApproach (int millisecondsTimeout) {
125                         throw new NotImplementedException ();
126                 }
127
128                 [PermissionSetAttribute (SecurityAction.LinkDemand, Name = "FullTrust")]
129                 [MonoTODO]
130                 public static GCNotificationStatus WaitForFullGCComplete () {
131                         throw new NotImplementedException ();
132                 }
133
134                 [PermissionSetAttribute (SecurityAction.LinkDemand, Name = "FullTrust")]
135                 [MonoTODO]
136                 public static GCNotificationStatus WaitForFullGCComplete (int millisecondsTimeout) {
137                         throw new NotImplementedException ();
138                 }
139
140                 [PermissionSetAttribute (SecurityAction.LinkDemand, Name = "FullTrust")]
141                 public static void RegisterForFullGCNotification (int maxGenerationThreshold, int largeObjectHeapThreshold) {
142                         if (maxGenerationThreshold < 1 || maxGenerationThreshold > 99)
143                                 throw new ArgumentOutOfRangeException ("maxGenerationThreshold", maxGenerationThreshold, "maxGenerationThreshold must be between 1 and 99 inclusive");
144                         if (largeObjectHeapThreshold < 1 || largeObjectHeapThreshold > 99)
145                                 throw new ArgumentOutOfRangeException ("largeObjectHeapThreshold", largeObjectHeapThreshold, "largeObjectHeapThreshold must be between 1 and 99 inclusive");
146                         throw new NotImplementedException ();
147                 }
148
149                 [PermissionSetAttribute (SecurityAction.LinkDemand, Name = "FullTrust")]
150                 public static void CancelFullGCNotification () {
151                         throw new NotImplementedException ();
152                 }
153 #endif
154
155 #if NET_4_0
156                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
157                 internal extern static void register_ephemeron_array (Ephemeron[] array);
158
159                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
160                 extern static object get_ephemeron_tombstone ();
161
162                 internal static readonly object EPHEMERON_TOMBSTONE = get_ephemeron_tombstone ();
163 #endif
164         }
165 }