test/java/lang/invoke/LFCaching/LambdaFormTestCase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File jdk Sdiff test/java/lang/invoke/LFCaching

test/java/lang/invoke/LFCaching/LambdaFormTestCase.java

Print this page
rev 11011 : 8067344: Adjust java/lang/invoke/LFCaching/LFGarbageCollectedTest.java for recent changes in java.lang.invoke
Reviewed-by: ?


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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 import com.oracle.testlibrary.jsr292.Helper;
  25 import com.sun.management.HotSpotDiagnosticMXBean;
  26 import java.lang.management.ManagementFactory;
  27 import java.lang.reflect.Method;
  28 import java.util.Collection;

  29 import java.util.function.Function;
  30 import jdk.testlibrary.Utils;
  31 
  32 /**
  33  * Lambda forms caching test case class. Contains all necessary test routines to
  34  * test lambda forms caching in method handles returned by methods of
  35  * MethodHandles class.
  36  *
  37  * @author kshefov
  38  */
  39 public abstract class LambdaFormTestCase {
  40 
  41     private final static String METHOD_HANDLE_CLASS_NAME = "java.lang.invoke.MethodHandle";
  42     private final static String INTERNAL_FORM_METHOD_NAME = "internalForm";
  43     private static final double ITERATIONS_TO_CODE_CACHE_SIZE_RATIO
  44             = 45 / (128.0 * 1024 * 1024);
  45     private static final long TIMEOUT = Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT);
  46 
  47     /**
  48      * Reflection link to {@code j.l.i.MethodHandle.internalForm} method. It is


 115         iterations = Math.min(iterationsByCodeCacheSize,
 116                 Math.min(iterations, iterationsByNonProfiledCodeCacheSize));
 117         if (iterations == 0) {
 118             System.out.println("Warning: code cache size is too small to provide at"
 119                     + " least one iteration! Test will try to do one iteration.");
 120             iterations = 1;
 121         }
 122         System.out.printf("Number of iterations is set to %d (%d cases)%n",
 123                 iterations, iterations * testCaseNum);
 124         System.out.flush();
 125         long startTime = System.currentTimeMillis();
 126         for (long i = 0; i < iterations; i++) {
 127             System.err.println(String.format("Iteration %d:", i));
 128             for (TestMethods testMethod : testMethods) {
 129                 LambdaFormTestCase testCase = ctor.apply(testMethod);
 130                 try {
 131                     System.err.printf("Tested LF caching feature with MethodHandles.%s method.%n",
 132                             testCase.getTestMethod().name);
 133                     testCase.doTest();
 134                     System.err.println("PASSED");




 135                 } catch (Throwable t) {
 136                     t.printStackTrace();
 137                     System.err.println("FAILED");
 138                     passed = false;
 139                     failCounter++;
 140                 }
 141                 testCounter++;
 142             }
 143             long passedTime = System.currentTimeMillis() - startTime;
 144             long avgIterTime = passedTime / (i + 1);
 145             long remainTime = TIMEOUT - passedTime;
 146             if (avgIterTime > 2 * remainTime) {
 147                 System.err.printf("Stopping iterations because of lack of time.%n"
 148                         + "Increase timeout factor for more iterations.%n");
 149                 break;
 150             }
 151         }
 152         if (!passed) {
 153             throw new Error(String.format("%d of %d test cases FAILED! %n"
 154                     + "Rerun the test with the same \"-Dseed=\" option as in the log file!",
 155                     failCounter, testCounter));
 156         } else {
 157             System.err.println(String.format("All %d test cases PASSED!", testCounter));
 158         }
 159     }








 160 }


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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 import com.oracle.testlibrary.jsr292.Helper;
  25 import com.sun.management.HotSpotDiagnosticMXBean;
  26 import java.lang.management.ManagementFactory;
  27 import java.lang.reflect.Method;
  28 import java.util.Collection;
  29 import java.util.Map;
  30 import java.util.function.Function;
  31 import jdk.testlibrary.Utils;
  32 
  33 /**
  34  * Lambda forms caching test case class. Contains all necessary test routines to
  35  * test lambda forms caching in method handles returned by methods of
  36  * MethodHandles class.
  37  *
  38  * @author kshefov
  39  */
  40 public abstract class LambdaFormTestCase {
  41 
  42     private final static String METHOD_HANDLE_CLASS_NAME = "java.lang.invoke.MethodHandle";
  43     private final static String INTERNAL_FORM_METHOD_NAME = "internalForm";
  44     private static final double ITERATIONS_TO_CODE_CACHE_SIZE_RATIO
  45             = 45 / (128.0 * 1024 * 1024);
  46     private static final long TIMEOUT = Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT);
  47 
  48     /**
  49      * Reflection link to {@code j.l.i.MethodHandle.internalForm} method. It is


 116         iterations = Math.min(iterationsByCodeCacheSize,
 117                 Math.min(iterations, iterationsByNonProfiledCodeCacheSize));
 118         if (iterations == 0) {
 119             System.out.println("Warning: code cache size is too small to provide at"
 120                     + " least one iteration! Test will try to do one iteration.");
 121             iterations = 1;
 122         }
 123         System.out.printf("Number of iterations is set to %d (%d cases)%n",
 124                 iterations, iterations * testCaseNum);
 125         System.out.flush();
 126         long startTime = System.currentTimeMillis();
 127         for (long i = 0; i < iterations; i++) {
 128             System.err.println(String.format("Iteration %d:", i));
 129             for (TestMethods testMethod : testMethods) {
 130                 LambdaFormTestCase testCase = ctor.apply(testMethod);
 131                 try {
 132                     System.err.printf("Tested LF caching feature with MethodHandles.%s method.%n",
 133                             testCase.getTestMethod().name);
 134                     testCase.doTest();
 135                     System.err.println("PASSED");
 136                 } catch (OutOfMemoryError e) {
 137                     // Don't swallow OOME so a heap dump can be created.
 138                     System.err.println("FAILED");
 139                     throw e;
 140                 } catch (Throwable t) {
 141                     t.printStackTrace();
 142                     System.err.println("FAILED");
 143                     passed = false;
 144                     failCounter++;
 145                 }
 146                 testCounter++;
 147             }
 148             long passedTime = System.currentTimeMillis() - startTime;
 149             long avgIterTime = passedTime / (i + 1);
 150             long remainTime = TIMEOUT - passedTime;
 151             if (avgIterTime > 2 * remainTime) {
 152                 System.err.printf("Stopping iterations because of lack of time.%n"
 153                         + "Increase timeout factor for more iterations.%n");
 154                 break;
 155             }
 156         }
 157         if (!passed) {
 158             throw new Error(String.format("%d of %d test cases FAILED! %n"
 159                     + "Rerun the test with the same \"-Dseed=\" option as in the log file!",
 160                     failCounter, testCounter));
 161         } else {
 162             System.err.println(String.format("All %d test cases PASSED!", testCounter));
 163         }
 164     }
 165 
 166     public void dumpTestCase() {
 167         System.out.println("Test case: " + getTestMethod());
 168         Map<String, Object> data = getTestMethod().getTestCaseData();
 169         for (String s : data.keySet()) {
 170             System.out.printf("\t%20s => %s\n", s, data.get(s));
 171         }
 172     }
 173 }
test/java/lang/invoke/LFCaching/LambdaFormTestCase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File