test/java/nio/channels/AsynchronousSocketChannel/Leaky.java

Print this page




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 4607272 6999915
  26  * @summary Unit test for AsynchronousSocketChannel
  27  * @run main/othervm -XX:+DisableExplicitGC -XX:MaxDirectMemorySize=64m Leaky
  28  */
  29 
  30 import java.nio.ByteBuffer;
  31 import java.nio.BufferPoolMXBean;
  32 import java.nio.channels.*;
  33 import java.net.*;
  34 import java.util.List;
  35 import java.util.concurrent.Future;
  36 import java.util.concurrent.ThreadFactory;

  37 import java.lang.management.ManagementFactory;
  38 
  39 /**
  40  * Heap buffers must be substituted with direct buffers when doing I/O. This
  41  * test creates a scenario on Windows that challenges the per-thread buffer
  42  * cache and quickly leads to an OutOfMemoryError if temporary buffers are
  43  * not returned to the native heap.
  44  */
  45 
  46 public class Leaky {
  47 
  48     static final int K = 1024;
  49 
  50     static class Connection {
  51         private final AsynchronousSocketChannel client;
  52         private final SocketChannel peer;
  53         private final ByteBuffer dst;
  54         private Future<Integer> readResult;
  55 
  56         Connection(AsynchronousChannelGroup group) throws Exception {




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 4607272 6999915
  26  * @summary Unit test for AsynchronousSocketChannel
  27  * @run main/othervm -XX:+DisableExplicitGC -XX:MaxDirectMemorySize=64m Leaky
  28  */
  29 
  30 import java.nio.ByteBuffer;

  31 import java.nio.channels.*;
  32 import java.net.*;
  33 import java.util.List;
  34 import java.util.concurrent.Future;
  35 import java.util.concurrent.ThreadFactory;
  36 import java.lang.management.BufferPoolMXBean;
  37 import java.lang.management.ManagementFactory;
  38 
  39 /**
  40  * Heap buffers must be substituted with direct buffers when doing I/O. This
  41  * test creates a scenario on Windows that challenges the per-thread buffer
  42  * cache and quickly leads to an OutOfMemoryError if temporary buffers are
  43  * not returned to the native heap.
  44  */
  45 
  46 public class Leaky {
  47 
  48     static final int K = 1024;
  49 
  50     static class Connection {
  51         private final AsynchronousSocketChannel client;
  52         private final SocketChannel peer;
  53         private final ByteBuffer dst;
  54         private Future<Integer> readResult;
  55 
  56         Connection(AsynchronousChannelGroup group) throws Exception {