10
10
package org .truffleruby .core ;
11
11
12
12
import java .lang .ref .ReferenceQueue ;
13
- import java .util .concurrent .locks .ReentrantLock ;
14
13
14
+ import com .oracle .truffle .api .interop .InteropException ;
15
15
import org .truffleruby .RubyContext ;
16
16
import org .truffleruby .RubyLanguage ;
17
- import org .truffleruby .core .MarkingService .ExtensionCallStack ;
18
- import org .truffleruby .core .mutex .MutexOperations ;
19
17
import org .truffleruby .language .Nil ;
20
18
import org .truffleruby .language .RubyBaseRootNode ;
21
19
import org .truffleruby .language .backtrace .InternalRootNode ;
22
20
23
21
import com .oracle .truffle .api .CallTarget ;
24
22
import com .oracle .truffle .api .CompilerDirectives ;
25
23
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
26
- import com .oracle .truffle .api .interop .ArityException ;
27
24
import com .oracle .truffle .api .interop .InteropLibrary ;
28
- import com .oracle .truffle .api .interop .UnsupportedMessageException ;
29
- import com .oracle .truffle .api .interop .UnsupportedTypeException ;
30
- import com .oracle .truffle .api .profiles .ConditionProfile ;
31
25
import com .oracle .truffle .api .frame .VirtualFrame ;
32
26
33
27
/** C-ext data finalizers are implemented with phantom references and reference queues, and are run in a dedicated Ruby
@@ -40,10 +34,8 @@ public final class DataObjectFinalizationService
40
34
public static final class DataObjectFinalizerRootNode extends RubyBaseRootNode implements InternalRootNode {
41
35
42
36
@ Child private InteropLibrary callNode ;
43
- private final ConditionProfile ownedProfile = ConditionProfile .create ();
44
37
45
- public DataObjectFinalizerRootNode (
46
- RubyLanguage language ) {
38
+ public DataObjectFinalizerRootNode (RubyLanguage language ) {
47
39
super (language , RubyLanguage .EMPTY_FRAME_DESCRIPTOR , null );
48
40
49
41
callNode = InteropLibrary .getFactory ().createDispatched (1 );
@@ -55,41 +47,17 @@ public Object execute(VirtualFrame frame) {
55
47
}
56
48
57
49
public Object execute (DataObjectFinalizerReference ref ) {
58
- if (getContext ().getOptions ().CEXT_LOCK ) {
59
- final ReentrantLock lock = getContext ().getCExtensionsLock ();
60
- boolean owned = ownedProfile .profile (lock .isHeldByCurrentThread ());
61
-
62
- if (!owned ) {
63
- MutexOperations .lockInternal (getContext (), lock , this );
64
- }
50
+ if (!getContext ().isFinalizing ()) {
65
51
try {
66
- runFinalizer (ref );
67
- } finally {
68
- if (!owned ) {
69
- MutexOperations .unlockInternal (lock );
70
- }
52
+ callNode .invokeMember (getContext ().getCoreLibrary ().truffleCExtModule , "run_data_finalizer" ,
53
+ ref .finalizerCFunction , ref .dataStruct );
54
+ } catch (InteropException e ) {
55
+ throw CompilerDirectives .shouldNotReachHere (e );
71
56
}
72
- } else {
73
- runFinalizer (ref );
74
57
}
75
58
return Nil .INSTANCE ;
76
59
}
77
60
78
- private void runFinalizer (DataObjectFinalizerReference ref ) throws Error {
79
- try {
80
- if (!getContext ().isFinalizing ()) {
81
- final ExtensionCallStack stack = getLanguage ().getCurrentFiber ().extensionCallStack ;
82
- stack .push (false , stack .getSpecialVariables (), stack .getBlock ());
83
- try {
84
- callNode .execute (ref .finalizerCFunction , ref .dataStruct );
85
- } finally {
86
- stack .pop ();
87
- }
88
- }
89
- } catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e ) {
90
- throw CompilerDirectives .shouldNotReachHere ("Data holder finalization on invalid object" );
91
- }
92
- }
93
61
}
94
62
95
63
private final CallTarget callTarget ;
@@ -127,8 +95,7 @@ protected void processReference(RubyContext context, RubyLanguage language,
127
95
}
128
96
129
97
@ TruffleBoundary
130
- protected void processReferenceInternal (RubyContext context , RubyLanguage language ,
131
- DataObjectFinalizerReference ref ) {
132
- callTarget .call (new Object []{ ref });
98
+ void processReferenceInternal (RubyContext context , RubyLanguage language , DataObjectFinalizerReference ref ) {
99
+ callTarget .call (ref );
133
100
}
134
101
}
0 commit comments