Implementation of GetLoopbackInterfaceIndex on Windows
[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                 [MonoDocumentationNote ("mode and blocking parameters ignored")]
66                 public static void Collect (int generation, GCCollectionMode mode, bool blocking) {
67                         Collect (generation);
68                 }
69
70                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
71                 public extern static int GetGeneration (object obj);
72
73                 public static int GetGeneration (WeakReference wo) {
74                         object obj = wo.Target;
75                         if (obj == null)
76                                 throw new ArgumentException ();
77                         return GetGeneration (obj);
78                 }
79
80                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
81                 public extern static long GetTotalMemory (bool forceFullCollection);
82
83                 /* this icall has weird semantics check the docs... */
84                 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
85                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
86                 public extern static void KeepAlive (object obj);
87                 
88                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
89                 public extern static void ReRegisterForFinalize (object obj);
90
91                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
92                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
93                 public extern static void SuppressFinalize (object obj);
94
95                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
96                 public extern static void WaitForPendingFinalizers ();
97
98                 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
99                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
100                 public extern static int CollectionCount (int generation);
101
102                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
103                 private extern static void RecordPressure (long bytesAllocated);
104
105                 public static void AddMemoryPressure (long bytesAllocated) {
106                         RecordPressure (bytesAllocated);
107                 }
108
109                 public static void RemoveMemoryPressure (long bytesAllocated) {
110                         RecordPressure (-bytesAllocated);
111                 }
112
113                 [PermissionSetAttribute (SecurityAction.LinkDemand, Name = "FullTrust")]
114                 [MonoTODO]
115                 public static GCNotificationStatus WaitForFullGCApproach () {
116                         throw new NotImplementedException ();
117                 }
118
119                 [PermissionSetAttribute (SecurityAction.LinkDemand, Name = "FullTrust")]
120                 [MonoTODO]
121                 public static GCNotificationStatus WaitForFullGCApproach (int millisecondsTimeout) {
122                         throw new NotImplementedException ();
123                 }
124
125                 [PermissionSetAttribute (SecurityAction.LinkDemand, Name = "FullTrust")]
126                 [MonoTODO]
127                 public static GCNotificationStatus WaitForFullGCComplete () {
128                         throw new NotImplementedException ();
129                 }
130
131                 [PermissionSetAttribute (SecurityAction.LinkDemand, Name = "FullTrust")]
132                 [MonoTODO]
133                 public static GCNotificationStatus WaitForFullGCComplete (int millisecondsTimeout) {
134                         throw new NotImplementedException ();
135                 }
136
137                 [PermissionSetAttribute (SecurityAction.LinkDemand, Name = "FullTrust")]
138                 public static void RegisterForFullGCNotification (int maxGenerationThreshold, int largeObjectHeapThreshold) {
139                         if (maxGenerationThreshold < 1 || maxGenerationThreshold > 99)
140                                 throw new ArgumentOutOfRangeException ("maxGenerationThreshold", maxGenerationThreshold, "maxGenerationThreshold must be between 1 and 99 inclusive");
141                         if (largeObjectHeapThreshold < 1 || largeObjectHeapThreshold > 99)
142                                 throw new ArgumentOutOfRangeException ("largeObjectHeapThreshold", largeObjectHeapThreshold, "largeObjectHeapThreshold must be between 1 and 99 inclusive");
143                         throw new NotImplementedException ();
144                 }
145
146                 [PermissionSetAttribute (SecurityAction.LinkDemand, Name = "FullTrust")]
147                 public static void CancelFullGCNotification () {
148                         throw new NotImplementedException ();
149                 }
150
151                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
152                 internal extern static void register_ephemeron_array (Ephemeron[] array);
153
154                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
155                 extern static object get_ephemeron_tombstone ();
156
157                 internal static readonly object EPHEMERON_TOMBSTONE = get_ephemeron_tombstone ();
158         }
159 }