79
79
import com .oracle .truffle .api .TruffleFile ;
80
80
import com .oracle .truffle .api .TruffleLanguage ;
81
81
import com .oracle .truffle .api .TruffleLogger ;
82
- import com .oracle .truffle .api .TruffleSafepoint ;
83
82
import com .oracle .truffle .api .debug .DebuggerTags ;
84
83
import com .oracle .truffle .api .frame .MaterializedFrame ;
85
84
import com .oracle .truffle .api .frame .VirtualFrame ;
101
100
import com .oracle .truffle .api .object .Shape ;
102
101
import com .oracle .truffle .api .source .Source ;
103
102
import com .oracle .truffle .api .source .Source .SourceBuilder ;
104
- import java .util .List ;
105
103
import java .util .Map ;
106
- import java .util .SortedMap ;
107
- import java .util .TreeMap ;
108
- import java .util .concurrent .LinkedBlockingQueue ;
109
104
110
105
@ TruffleLanguage .Registration (id = PythonLanguage .ID , //
111
106
name = PythonLanguage .NAME , //
@@ -227,8 +222,6 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
227
222
228
223
private final Map <Long , ChildContextData > childContextData = new ConcurrentHashMap <>();
229
224
230
- private final SharedMultiprocessingData sharedMPData = new SharedMultiprocessingData ();
231
-
232
225
@ TruffleBoundary
233
226
public Thread getChildContextThread (long tid ) {
234
227
return childContextThreads .get (tid );
@@ -254,19 +247,10 @@ public void putChildContextData(long id, ChildContextData data) {
254
247
childContextData .put (id , data );
255
248
}
256
249
257
- @ TruffleBoundary
258
- public void removeChildContextData (long id ) {
259
- childContextData .remove (id );
260
- }
261
-
262
250
public static PythonLanguage get (Node node ) {
263
251
return REFERENCE .get (node );
264
252
}
265
253
266
- public synchronized SharedMultiprocessingData getSharedMultiprocessingData () {
267
- return sharedMPData ;
268
- }
269
-
270
254
public static int getNumberOfSpecialSingletons () {
271
255
return CONTEXT_INSENSITIVE_SINGLETONS .length ;
272
256
}
@@ -895,103 +879,4 @@ public RootCallTarget getDescriptorCallTarget(BuiltinMethodDescriptor descriptor
895
879
return callTarget ;
896
880
}
897
881
898
- public static class SharedMultiprocessingData {
899
-
900
- private final SortedMap <Integer , LinkedBlockingQueue <Object >> sharedContextData = new TreeMap <>();
901
-
902
- /**
903
- * @return fake (negative) fd values to avoid clash with real file descriptors and to detect
904
- * potential usage by other python builtins
905
- */
906
- @ TruffleBoundary
907
- public int [] pipe () {
908
- synchronized (sharedContextData ) {
909
- LinkedBlockingQueue <Object > q = new LinkedBlockingQueue <>();
910
- int readFD = nextFreeFd ();
911
- sharedContextData .put (readFD , q );
912
- int writeFD = nextFreeFd ();
913
- sharedContextData .put (writeFD , q );
914
- return new int []{readFD , writeFD };
915
- }
916
- }
917
-
918
- /**
919
- * Must be called in a synchronized (sharedContextData) block which also writes the new fd
920
- * into the sharedContextData map.
921
- */
922
- @ TruffleBoundary
923
- private int nextFreeFd () {
924
- if (sharedContextData .isEmpty ()) {
925
- return -1 ;
926
- }
927
- return sharedContextData .firstKey () - 1 ;
928
- }
929
-
930
- @ TruffleBoundary
931
- public boolean hasFD (int fd ) {
932
- synchronized (sharedContextData ) {
933
- return sharedContextData .containsKey (fd );
934
- }
935
- }
936
-
937
- @ TruffleBoundary
938
- public boolean addSharedContextData (int fd , byte [] bytes , Runnable noFDHandler ) {
939
- LinkedBlockingQueue <Object > q = getQueue (fd );
940
- if (q == null ) {
941
- noFDHandler .run ();
942
- return false ;
943
- }
944
- q .add (bytes );
945
- return true ;
946
- }
947
-
948
- @ TruffleBoundary
949
- public void makeReadable (int fd , Runnable noFDHandler ) {
950
- LinkedBlockingQueue <Object > q = getQueue (fd );
951
- if (q == null ) {
952
- noFDHandler .run ();
953
- return ;
954
- }
955
- q .add (PythonUtils .EMPTY_BYTE_ARRAY );
956
- }
957
-
958
- @ TruffleBoundary
959
- public Object takeSharedContextData (Node node , int fd , Runnable noFDHandler ) {
960
- LinkedBlockingQueue <Object > q = getQueue (fd );
961
- if (q == null ) {
962
- noFDHandler .run ();
963
- return null ;
964
- }
965
- Object [] o = new Object []{PNone .NONE };
966
- TruffleSafepoint .setBlockedThreadInterruptible (node , (lbq ) -> {
967
- o [0 ] = lbq .take ();
968
- }, q );
969
- return o [0 ];
970
- }
971
-
972
- @ TruffleBoundary
973
- public boolean isEmpty (int fd , Runnable noFDHandler ) {
974
- LinkedBlockingQueue <Object > q = getQueue (fd );
975
- if (q == null ) {
976
- noFDHandler .run ();
977
- return false ;
978
- }
979
- return q .isEmpty ();
980
- }
981
-
982
- @ TruffleBoundary
983
- public void closeFDs (List <Integer > fds ) {
984
- synchronized (sharedContextData ) {
985
- for (Integer fd : fds ) {
986
- sharedContextData .remove (fd );
987
- }
988
- }
989
- }
990
-
991
- private LinkedBlockingQueue <Object > getQueue (int fd ) {
992
- synchronized (sharedContextData ) {
993
- return sharedContextData .get (fd );
994
- }
995
- }
996
- }
997
882
}
0 commit comments