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