29
29
import java .lang .management .ManagementFactory ;
30
30
import java .util .List ;
31
31
32
+ import com .oracle .graal .python .PythonLanguage ;
32
33
import com .oracle .graal .python .builtins .Builtin ;
33
34
import com .oracle .graal .python .builtins .CoreFunctions ;
34
35
import com .oracle .graal .python .builtins .PythonBuiltins ;
38
39
import com .oracle .graal .python .builtins .objects .list .PList ;
39
40
import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
40
41
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
42
+ import com .oracle .graal .python .runtime .PythonContext ;
43
+ import com .oracle .graal .python .runtime .PythonCore ;
44
+ import com .oracle .graal .python .util .PythonUtils ;
41
45
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
42
46
import com .oracle .truffle .api .dsl .Cached ;
47
+ import com .oracle .truffle .api .dsl .CachedContext ;
43
48
import com .oracle .truffle .api .dsl .Fallback ;
44
49
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
45
50
import com .oracle .truffle .api .dsl .Specialization ;
@@ -54,48 +59,70 @@ protected List<com.oracle.truffle.api.dsl.NodeFactory<? extends PythonBuiltinNod
54
59
return GcModuleBuiltinsFactory .getFactories ();
55
60
}
56
61
62
+ @ Override
63
+ public void initialize (PythonCore core ) {
64
+ builtinConstants .put ("DEBUG_LEAK" , 0 );
65
+ super .initialize (core );
66
+ }
67
+
57
68
@ Builtin (name = "collect" , minNumOfPositionalArgs = 0 , maxNumOfPositionalArgs = 1 )
58
69
@ GenerateNodeFactory
59
70
abstract static class GcCollectNode extends PythonBuiltinNode {
60
71
@ Specialization
61
72
int collect (VirtualFrame frame , @ SuppressWarnings ("unused" ) Object level ,
62
73
@ Cached BranchProfile asyncProfile ) {
63
- doGc ();
74
+ PythonUtils . forceFullGC ();
64
75
// collect some weak references now
65
76
getContext ().triggerAsyncActions (frame , asyncProfile );
66
77
return 0 ;
67
78
}
68
-
69
- @ TruffleBoundary
70
- private static void doGc () {
71
- System .gc ();
72
- }
73
79
}
74
80
75
81
@ Builtin (name = "isenabled" , minNumOfPositionalArgs = 0 )
76
82
@ GenerateNodeFactory
77
83
abstract static class GcIsEnabledNode extends PythonBuiltinNode {
78
84
@ Specialization
79
- boolean isenabled () {
80
- return true ;
85
+ boolean isenabled (@ CachedContext ( PythonLanguage . class ) PythonContext ctx ) {
86
+ return ctx . isGcEnabled () ;
81
87
}
82
88
}
83
89
84
- abstract static class StubNode extends PythonBuiltinNode {
90
+ @ Builtin (name = "disable" , minNumOfPositionalArgs = 0 )
91
+ @ GenerateNodeFactory
92
+ abstract static class DisableNode extends PythonBuiltinNode {
85
93
@ Specialization
86
- PNone disable () {
94
+ PNone disable (@ CachedContext (PythonLanguage .class ) PythonContext ctx ) {
95
+ ctx .setGcEnabled (false );
87
96
return PNone .NONE ;
88
97
}
89
98
}
90
99
91
- @ Builtin (name = "disable" , minNumOfPositionalArgs = 0 )
100
+ @ Builtin (name = "enable" , minNumOfPositionalArgs = 0 )
101
+ @ GenerateNodeFactory
102
+ abstract static class EnableNode extends PythonBuiltinNode {
103
+ @ Specialization
104
+ PNone enable (@ CachedContext (PythonLanguage .class ) PythonContext ctx ) {
105
+ ctx .setGcEnabled (true );
106
+ return PNone .NONE ;
107
+ }
108
+ }
109
+
110
+ @ Builtin (name = "get_debug" , minNumOfPositionalArgs = 0 )
92
111
@ GenerateNodeFactory
93
- abstract static class DisableNode extends StubNode {
112
+ abstract static class GetDebugNode extends PythonBuiltinNode {
113
+ @ Specialization
114
+ int getDebug () {
115
+ return 0 ;
116
+ }
94
117
}
95
118
96
- @ Builtin (name = "enable " , minNumOfPositionalArgs = 0 )
119
+ @ Builtin (name = "set_debug " , minNumOfPositionalArgs = 1 )
97
120
@ GenerateNodeFactory
98
- abstract static class EnableNode extends StubNode {
121
+ abstract static class SetDebugNode extends PythonBuiltinNode {
122
+ @ Specialization
123
+ PNone setDebug (@ SuppressWarnings ("unused" ) Object ignored ) {
124
+ return PNone .NONE ;
125
+ }
99
126
}
100
127
101
128
@ Builtin (name = "get_count" , minNumOfPositionalArgs = 0 )
0 commit comments