1
1
/*
2
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* The Universal Permissive License (UPL), Version 1.0
47
47
import java .util .ArrayList ;
48
48
import java .util .Collections ;
49
49
import java .util .List ;
50
+ import java .util .Map ;
51
+ import java .util .concurrent .ConcurrentHashMap ;
50
52
51
53
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
52
54
import com .oracle .truffle .api .TruffleFile ;
@@ -65,6 +67,8 @@ public class PosixResources {
65
67
private final List <Channel > files ;
66
68
private final List <String > filePaths ;
67
69
private final List <Process > children ;
70
+ private final Map <String , Integer > inodes ;
71
+ private int inodeCnt = 0 ;
68
72
69
73
public PosixResources () {
70
74
files = Collections .synchronizedList (new ArrayList <>());
@@ -82,6 +86,7 @@ public PosixResources() {
82
86
files .add (null );
83
87
files .add (null );
84
88
files .add (null );
89
+ inodes = new ConcurrentHashMap <>();
85
90
}
86
91
87
92
@ TruffleBoundary (allowInlining = true )
@@ -198,4 +203,16 @@ public int waitpid(int pid) throws ArrayIndexOutOfBoundsException, InterruptedEx
198
203
children .set (pid , null );
199
204
return exitStatus ;
200
205
}
206
+
207
+ @ TruffleBoundary (allowInlining = true )
208
+ public int getInodeId (String canonical ) {
209
+ int inodeId ;
210
+ if (!inodes .containsKey (canonical )) {
211
+ inodeId = inodeCnt ++;
212
+ inodes .put (canonical , inodeId );
213
+ } else {
214
+ inodeId = inodes .get (canonical );
215
+ }
216
+ return inodeId ;
217
+ }
201
218
}
0 commit comments