|
1 | | -// |
| 1 | +// |
2 | 2 | // Copyright (c) .NET Foundation and Contributors |
3 | 3 | // Portions Copyright (c) Microsoft Corporation. All rights reserved. |
4 | 4 | // See LICENSE file in the project root for full license information. |
5 | 5 | // |
6 | 6 | #include "CorLib.h" |
7 | 7 |
|
8 | | -HRESULT Library_corlib_native_System_GC::AnyPendingFinalizers___STATIC__BOOLEAN(CLR_RT_StackFrame &stack) |
| 8 | +HRESULT Library_corlib_native_System_GC::EnableGCMessages___STATIC__VOID__BOOLEAN( |
| 9 | + CLR_RT_StackFrame &stack) |
9 | 10 | { |
10 | 11 | NATIVE_PROFILE_CLR_CORE(); |
| 12 | + |
11 | 13 | NANOCLR_HEADER(); |
12 | 14 |
|
13 | | - stack.SetResult_Boolean( |
14 | | - g_CLR_RT_ExecutionEngine.m_finalizersPending.IsEmpty() == false || |
15 | | - (g_CLR_RT_ExecutionEngine.m_finalizerThread != nullptr && |
16 | | - !g_CLR_RT_ExecutionEngine.m_finalizerThread->CanThreadBeReused())); |
| 15 | +#if defined(NANOCLR_TRACE_MEMORY_STATS) |
| 16 | + s_CLR_RT_fTrace_MemoryStats = stack.Arg0().NumericByRefConst().u1 != 0 ? c_CLR_RT_Trace_Info : c_CLR_RT_Trace_None; |
| 17 | +#else |
| 18 | + (void)stack; |
| 19 | +#endif |
17 | 20 |
|
18 | 21 | NANOCLR_NOCLEANUP_NOLABEL(); |
19 | 22 | } |
20 | 23 |
|
21 | | -HRESULT Library_corlib_native_System_GC::SuppressFinalize___STATIC__VOID__OBJECT(CLR_RT_StackFrame &stack) |
| 24 | +HRESULT Library_corlib_native_System_GC::ReRegisterForFinalize___STATIC__VOID__OBJECT(CLR_RT_StackFrame &stack) |
22 | 25 | { |
23 | 26 | NATIVE_PROFILE_CLR_CORE(); |
24 | 27 | NANOCLR_HEADER(); |
25 | 28 |
|
| 29 | + CLR_RT_TypeDescriptor desc{}; |
26 | 30 | CLR_RT_HeapBlock *pObj = stack.Arg0().Dereference(); |
27 | 31 | FAULT_ON_NULL(pObj); |
28 | 32 |
|
29 | 33 | CLR_RT_HeapBlock_Finalizer::SuppressFinalize(pObj); |
30 | 34 |
|
| 35 | + NANOCLR_CHECK_HRESULT(desc.InitializeFromObject(stack.Arg0())); |
| 36 | + |
| 37 | + if (desc.m_handlerCls.HasFinalizer()) |
| 38 | + { |
| 39 | + NANOCLR_CHECK_HRESULT( |
| 40 | + CLR_RT_HeapBlock_Finalizer::CreateInstance(stack.Arg0().Dereference(), desc.m_handlerCls)); |
| 41 | + } |
| 42 | + |
31 | 43 | NANOCLR_NOCLEANUP(); |
32 | 44 | } |
33 | 45 |
|
34 | | -HRESULT Library_corlib_native_System_GC::ReRegisterForFinalize___STATIC__VOID__OBJECT(CLR_RT_StackFrame &stack) |
| 46 | +HRESULT Library_corlib_native_System_GC::SuppressFinalize___STATIC__VOID__OBJECT(CLR_RT_StackFrame &stack) |
35 | 47 | { |
36 | 48 | NATIVE_PROFILE_CLR_CORE(); |
37 | 49 | NANOCLR_HEADER(); |
38 | 50 |
|
39 | | - CLR_RT_TypeDescriptor desc{}; |
40 | 51 | CLR_RT_HeapBlock *pObj = stack.Arg0().Dereference(); |
41 | 52 | FAULT_ON_NULL(pObj); |
42 | 53 |
|
43 | 54 | CLR_RT_HeapBlock_Finalizer::SuppressFinalize(pObj); |
44 | 55 |
|
45 | | - NANOCLR_CHECK_HRESULT(desc.InitializeFromObject(stack.Arg0())); |
| 56 | + NANOCLR_NOCLEANUP(); |
| 57 | +} |
46 | 58 |
|
47 | | - if (desc.m_handlerCls.HasFinalizer()) |
| 59 | +HRESULT Library_corlib_native_System_GC::AnyPendingFinalizers___STATIC__BOOLEAN(CLR_RT_StackFrame &stack) |
| 60 | +{ |
| 61 | + NATIVE_PROFILE_CLR_CORE(); |
| 62 | + NANOCLR_HEADER(); |
| 63 | + |
| 64 | + stack.SetResult_Boolean( |
| 65 | + g_CLR_RT_ExecutionEngine.m_finalizersPending.IsEmpty() == false || |
| 66 | + (g_CLR_RT_ExecutionEngine.m_finalizerThread != nullptr && |
| 67 | + !g_CLR_RT_ExecutionEngine.m_finalizerThread->CanThreadBeReused())); |
| 68 | + |
| 69 | + NANOCLR_NOCLEANUP_NOLABEL(); |
| 70 | +} |
| 71 | + |
| 72 | +HRESULT Library_corlib_native_System_GC::Run___STATIC__U4__BOOLEAN(CLR_RT_StackFrame &stack) |
| 73 | +{ |
| 74 | + NATIVE_PROFILE_CLR_CORE(); |
| 75 | + |
| 76 | + NANOCLR_HEADER(); |
| 77 | + |
| 78 | +#if defined(NANOCLR_GC_VERBOSE) |
| 79 | + if (s_CLR_RT_fTrace_GC >= c_CLR_RT_Trace_Info) |
48 | 80 | { |
49 | | - NANOCLR_CHECK_HRESULT( |
50 | | - CLR_RT_HeapBlock_Finalizer::CreateInstance(stack.Arg0().Dereference(), desc.m_handlerCls)); |
| 81 | + CLR_Debug::Printf(" Memory: Debug.GC.\r\n"); |
51 | 82 | } |
| 83 | +#endif |
52 | 84 |
|
53 | | - NANOCLR_NOCLEANUP(); |
| 85 | + stack.SetResult_I4(g_CLR_RT_ExecutionEngine.PerformGarbageCollection()); |
| 86 | + |
| 87 | + if (stack.Arg0().NumericByRefConst().u1) |
| 88 | + { |
| 89 | + // |
| 90 | + // Decrement the number of GC, otherwise the outer loop may request another compaction. |
| 91 | + // |
| 92 | + g_CLR_RT_GarbageCollector.m_numberOfGarbageCollections--; |
| 93 | + |
| 94 | + g_CLR_RT_ExecutionEngine.PerformHeapCompaction(); |
| 95 | + } |
| 96 | + |
| 97 | + NANOCLR_NOCLEANUP_NOLABEL(); |
54 | 98 | } |
0 commit comments