15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 /*
27 * KQueueArrayWrapper.java
28 * Implementation of Selector using FreeBSD / Mac OS X kqueues
29 * Derived from Sun's DevPollArrayWrapper
30 */
31
32 package sun.nio.ch;
33
34 import java.io.IOException;
35 import java.io.FileDescriptor;
36 import java.util.Iterator;
37 import java.util.LinkedList;
38
39 /*
40 * struct kevent { // 32-bit 64-bit
41 * uintptr_t ident; // 4 8
42 * short filter; // 2 2
43 * u_short flags; // 2 2
44 * u_int fflags; // 4 4
45 * intptr_t data; // 4 8
46 * void *udata; // 4 8
47 * } // Total: 20 32
48 *
49 * The implementation works in 32-bit and 64-bit world. We do this by calling a
50 * native function that actually sets the sizes and offsets of the fields based
51 * on which mode we're in.
52 */
53
54 class KQueueArrayWrapper {
55 // kevent filters
56 static short EVFILT_READ;
57 static short EVFILT_WRITE;
67
68 // Are we in a 64-bit VM?
69 static boolean is64bit = false;
70
71 // The kevent array (used for outcoming events only)
72 private AllocatedNativeObject keventArray = null;
73 private long keventArrayAddress;
74
75 // The kqueue fd
76 private int kq = -1;
77
78 // The fd of the interrupt line going out
79 private int outgoingInterruptFD;
80
81 // The fd of the interrupt line coming in
82 private int incomingInterruptFD;
83
84 static {
85 IOUtil.load();
86 initStructSizes();
87 String datamodel = java.security.AccessController.doPrivileged(
88 new sun.security.action.GetPropertyAction("sun.arch.data.model")
89 );
90 is64bit = datamodel.equals("64");
91 }
92
93 KQueueArrayWrapper() {
94 int allocationSize = SIZEOF_KEVENT * NUM_KEVENTS;
95 keventArray = new AllocatedNativeObject(allocationSize, true);
96 keventArrayAddress = keventArray.address();
97 kq = init();
98 }
99
100 // Used to update file description registrations
101 private static class Update {
102 SelChImpl channel;
103 int events;
104 Update(SelChImpl channel, int events) {
105 this.channel = channel;
106 this.events = events;
107 }
108 }
109
110 private LinkedList<Update> updateList = new LinkedList<Update>();
|
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 /*
27 * KQueueArrayWrapper.java
28 * Implementation of Selector using FreeBSD / Mac OS X kqueues
29 * Derived from Sun's DevPollArrayWrapper
30 */
31
32 package sun.nio.ch;
33
34 import java.io.IOException;
35 import java.util.Iterator;
36 import java.util.LinkedList;
37 import sun.security.action.GetPropertyAction;
38
39 /*
40 * struct kevent { // 32-bit 64-bit
41 * uintptr_t ident; // 4 8
42 * short filter; // 2 2
43 * u_short flags; // 2 2
44 * u_int fflags; // 4 4
45 * intptr_t data; // 4 8
46 * void *udata; // 4 8
47 * } // Total: 20 32
48 *
49 * The implementation works in 32-bit and 64-bit world. We do this by calling a
50 * native function that actually sets the sizes and offsets of the fields based
51 * on which mode we're in.
52 */
53
54 class KQueueArrayWrapper {
55 // kevent filters
56 static short EVFILT_READ;
57 static short EVFILT_WRITE;
67
68 // Are we in a 64-bit VM?
69 static boolean is64bit = false;
70
71 // The kevent array (used for outcoming events only)
72 private AllocatedNativeObject keventArray = null;
73 private long keventArrayAddress;
74
75 // The kqueue fd
76 private int kq = -1;
77
78 // The fd of the interrupt line going out
79 private int outgoingInterruptFD;
80
81 // The fd of the interrupt line coming in
82 private int incomingInterruptFD;
83
84 static {
85 IOUtil.load();
86 initStructSizes();
87 String datamodel = GetPropertyAction.getProperty("sun.arch.data.model");
88 is64bit = "64".equals(datamodel);
89 }
90
91 KQueueArrayWrapper() {
92 int allocationSize = SIZEOF_KEVENT * NUM_KEVENTS;
93 keventArray = new AllocatedNativeObject(allocationSize, true);
94 keventArrayAddress = keventArray.address();
95 kq = init();
96 }
97
98 // Used to update file description registrations
99 private static class Update {
100 SelChImpl channel;
101 int events;
102 Update(SelChImpl channel, int events) {
103 this.channel = channel;
104 this.events = events;
105 }
106 }
107
108 private LinkedList<Update> updateList = new LinkedList<Update>();
|