< prev index next >

src/java.base/linux/classes/sun/nio/fs/LinuxWatchService.java

Print this page
rev 55686 : 8227587: Add internal privileged System.loadLibrary
Reviewed-by: rriggs, mchung
   1 /*
   2  * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  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 package sun.nio.fs;
  27 
  28 import java.nio.file.*;
  29 import java.security.AccessController;
  30 import java.security.PrivilegedAction;
  31 import java.util.*;
  32 import java.io.IOException;
  33 import jdk.internal.misc.Unsafe;
  34 
  35 import static sun.nio.fs.UnixNativeDispatcher.*;
  36 import static sun.nio.fs.UnixConstants.*;
  37 
  38 /**
  39  * Linux implementation of WatchService based on inotify.
  40  *
  41  * In summary a background thread polls inotify plus a socket used for the wakeup
  42  * mechanism. Requests to add or remove a watch, or close the watch service,
  43  * cause the thread to wakeup and process the request. Events are processed
  44  * by the thread which causes it to signal/queue the corresponding watch keys.
  45  */
  46 
  47 class LinuxWatchService
  48     extends AbstractWatchService
  49 {
  50     private static final Unsafe unsafe = Unsafe.getUnsafe();


 442 
 443     // offsets of inotify_event
 444     private static native int[] eventOffsets();
 445 
 446     private static native int inotifyInit() throws UnixException;
 447 
 448     private static native int inotifyAddWatch(int fd, long pathAddress, int mask)
 449         throws UnixException;
 450 
 451     private static native void inotifyRmWatch(int fd, int wd)
 452         throws UnixException;
 453 
 454     private static native void configureBlocking(int fd, boolean blocking)
 455         throws UnixException;
 456 
 457     private static native void socketpair(int[] sv) throws UnixException;
 458 
 459     private static native int poll(int fd1, int fd2) throws UnixException;
 460 
 461     static {
 462         AccessController.doPrivileged(new PrivilegedAction<>() {
 463             public Void run() {
 464                 System.loadLibrary("nio");
 465                 return null;
 466         }});
 467     }
 468 }
   1 /*
   2  * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  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 package sun.nio.fs;
  27 
  28 import java.nio.file.*;


  29 import java.util.*;
  30 import java.io.IOException;
  31 import jdk.internal.misc.Unsafe;
  32 
  33 import static sun.nio.fs.UnixNativeDispatcher.*;
  34 import static sun.nio.fs.UnixConstants.*;
  35 
  36 /**
  37  * Linux implementation of WatchService based on inotify.
  38  *
  39  * In summary a background thread polls inotify plus a socket used for the wakeup
  40  * mechanism. Requests to add or remove a watch, or close the watch service,
  41  * cause the thread to wakeup and process the request. Events are processed
  42  * by the thread which causes it to signal/queue the corresponding watch keys.
  43  */
  44 
  45 class LinuxWatchService
  46     extends AbstractWatchService
  47 {
  48     private static final Unsafe unsafe = Unsafe.getUnsafe();


 440 
 441     // offsets of inotify_event
 442     private static native int[] eventOffsets();
 443 
 444     private static native int inotifyInit() throws UnixException;
 445 
 446     private static native int inotifyAddWatch(int fd, long pathAddress, int mask)
 447         throws UnixException;
 448 
 449     private static native void inotifyRmWatch(int fd, int wd)
 450         throws UnixException;
 451 
 452     private static native void configureBlocking(int fd, boolean blocking)
 453         throws UnixException;
 454 
 455     private static native void socketpair(int[] sv) throws UnixException;
 456 
 457     private static native int poll(int fd1, int fd2) throws UnixException;
 458 
 459     static {
 460         jdk.internal.loader.BootLoader.loadLibrary("nio");




 461     }
 462 }
< prev index next >