Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/channels/FileChannel/LoopingTruncate.java
38828 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 8137121 813723026* @summary (fc) Infinite loop FileChannel.truncate27* @library /lib/testlibrary28* @build jdk.testlibrary.Utils29* @run main/othervm LoopingTruncate30*/3132import java.nio.ByteBuffer;33import java.nio.channels.FileChannel;34import java.nio.channels.ClosedByInterruptException;35import java.nio.file.Files;36import java.nio.file.Path;37import static java.nio.file.StandardOpenOption.*;38import static jdk.testlibrary.Utils.adjustTimeout;3940public class LoopingTruncate {4142// (int)FATEFUL_SIZE == -3 == IOStatus.INTERRUPTED43static long FATEFUL_SIZE = 0x1FFFFFFFDL;4445// At least 20 seconds46static long TIMEOUT = adjustTimeout(20_000);4748public static void main(String[] args) throws Throwable {49Path path = Files.createTempFile("LoopingTruncate.tmp", null);50try (FileChannel fc = FileChannel.open(path, CREATE, WRITE)) {51fc.position(FATEFUL_SIZE + 1L);52fc.write(ByteBuffer.wrap(new byte[] {0}));5354Thread th = new Thread(() -> {55try {56fc.truncate(FATEFUL_SIZE);57} catch (ClosedByInterruptException ignore) {58} catch (Exception e) {59throw new RuntimeException(e);60}});61th.start();62th.join(TIMEOUT);6364if (th.isAlive()) {65System.err.println("=== Stack trace of the guilty thread:");66for (StackTraceElement el : th.getStackTrace()) {67System.err.println("\t" + el);68}69System.err.println("===");7071th.interrupt();72th.join();73throw new RuntimeException("Failed to complete on time");74}75} finally {76Files.deleteIfExists(path);77}78}79}808182