7979import com .oracle .truffle .api .TruffleFile ;
8080import com .oracle .truffle .api .TruffleLanguage ;
8181import com .oracle .truffle .api .TruffleLogger ;
82- import com .oracle .truffle .api .TruffleSafepoint ;
8382import com .oracle .truffle .api .debug .DebuggerTags ;
8483import com .oracle .truffle .api .frame .MaterializedFrame ;
8584import com .oracle .truffle .api .frame .VirtualFrame ;
101100import com .oracle .truffle .api .object .Shape ;
102101import com .oracle .truffle .api .source .Source ;
103102import com .oracle .truffle .api .source .Source .SourceBuilder ;
104- import java .util .List ;
105103import java .util .Map ;
106- import java .util .SortedMap ;
107- import java .util .TreeMap ;
108- import java .util .concurrent .LinkedBlockingQueue ;
109104
110105@ TruffleLanguage .Registration (id = PythonLanguage .ID , //
111106 name = PythonLanguage .NAME , //
@@ -227,8 +222,6 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
227222
228223 private final Map <Long , ChildContextData > childContextData = new ConcurrentHashMap <>();
229224
230- private final SharedMultiprocessingData sharedMPData = new SharedMultiprocessingData ();
231-
232225 @ TruffleBoundary
233226 public Thread getChildContextThread (long tid ) {
234227 return childContextThreads .get (tid );
@@ -254,19 +247,10 @@ public void putChildContextData(long id, ChildContextData data) {
254247 childContextData .put (id , data );
255248 }
256249
257- @ TruffleBoundary
258- public void removeChildContextData (long id ) {
259- childContextData .remove (id );
260- }
261-
262250 public static PythonLanguage get (Node node ) {
263251 return REFERENCE .get (node );
264252 }
265253
266- public synchronized SharedMultiprocessingData getSharedMultiprocessingData () {
267- return sharedMPData ;
268- }
269-
270254 public static int getNumberOfSpecialSingletons () {
271255 return CONTEXT_INSENSITIVE_SINGLETONS .length ;
272256 }
@@ -895,103 +879,4 @@ public RootCallTarget getDescriptorCallTarget(BuiltinMethodDescriptor descriptor
895879 return callTarget ;
896880 }
897881
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- }
997882}
0 commit comments