--- old/test/java/lang/invoke/MethodHandles/CatchExceptionTest.java 2014-11-29 17:37:28.416917437 +0300 +++ new/test/java/lang/invoke/MethodHandles/CatchExceptionTest.java 2014-11-29 17:37:28.252917439 +0300 @@ -24,6 +24,8 @@ import com.oracle.testlibrary.jsr292.Helper; import jdk.testlibrary.Asserts; +import jdk.testlibrary.TimeLimitedRunner; +import jdk.testlibrary.Utils; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -33,6 +35,7 @@ import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; +import java.util.concurrent.TimeUnit; /* @test * @library /lib/testlibrary/jsr292 /lib/testlibrary/ @@ -93,14 +96,23 @@ } public static void main(String[] args) throws Throwable { - for (CatchExceptionTest test : TestFactory.MANDATORY_TEST_CASES) { - test.runTest(); - } TestFactory factory = new TestFactory(); - CatchExceptionTest test; - while ((test = factory.nextTest()) != null ) { + long timeout = Helper.IS_THOROUGH ? 0L : Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT); + // substract vm init time and reserve time for vm exit + timeout *= 0.9; + TimeLimitedRunner runner = new TimeLimitedRunner(timeout, + () -> { + CatchExceptionTest test = factory.nextTest(); + if (test != null) { + test.runTest(); + return true; + } + return false; + }); + for (CatchExceptionTest test : TestFactory.MANDATORY_TEST_CASES) { test.runTest(); } + runner.call(); } private List> getThrowerParams(boolean isVararg, int argsCount) { --- /dev/null 2014-11-18 17:23:07.628909932 +0300 +++ new/test/lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java 2014-11-29 17:37:28.356917438 +0300 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.testlibrary; + +import java.util.Objects; +import java.util.concurrent.Callable; + +/** + * Auxiliary class to run target w/ given timeout. + */ +public class TimeLimitedRunner implements Callable { + private final long stoptime; + private final long timeout; + private final Callable target; + + /** + * @param timeout a timeout. zero means no time limitation + * @param target a target to run + * @throws NullPointerException if target is null + * @throws IllegalArgumentException if timeout is negative + */ + public TimeLimitedRunner(long timeout, Callable target) { + Objects.requireNonNull(target, "target must not be null"); + if (timeout < 0) { + throw new IllegalArgumentException("timeout[" + timeout + "] < 0"); + } + this.stoptime = System.currentTimeMillis() + timeout; + this.timeout = timeout; + this.target = target; + } + + /** + * Runs @{linkplan target} while it returns true and timeout isn't exceeded + */ + @Override + public Void call() throws Exception { + long maxDuration = 0L; + long iterStart = System.currentTimeMillis(); + if (timeout != 0 && iterStart > stoptime) { + return null; + } + while (target.call()) { + if (timeout != 0) { + long iterDuration = System.currentTimeMillis() - iterStart; + maxDuration = Math.max(maxDuration, iterDuration); + iterStart = System.currentTimeMillis(); + if (iterStart + (maxDuration << 1) > stoptime) { + System.out.println("Not enough time to continue execution. " + + "Interrupted."); + break; + } + } + } + return null; + } + +}