Mercurial > hg > graal-compiler
comparison test/compiler/whitebox/CompilerWhiteBoxTest.java @ 8766:4efac99a998b
8008211: Some of WB tests on compiler fail
Reviewed-by: kvn, vlivanov
author | iignatyev |
---|---|
date | Mon, 18 Mar 2013 04:29:08 -0700 |
parents | 12e01444ca2d |
children | b84fd7d73702 |
comparison
equal
deleted
inserted
replaced
8765:592f9722c72e | 8766:4efac99a998b |
---|---|
33 public abstract class CompilerWhiteBoxTest { | 33 public abstract class CompilerWhiteBoxTest { |
34 protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); | 34 protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); |
35 protected static final Method METHOD = getMethod("method"); | 35 protected static final Method METHOD = getMethod("method"); |
36 protected static final int COMPILE_THRESHOLD | 36 protected static final int COMPILE_THRESHOLD |
37 = Integer.parseInt(getVMOption("CompileThreshold", "10000")); | 37 = Integer.parseInt(getVMOption("CompileThreshold", "10000")); |
38 protected static final boolean BACKGROUND_COMPILATION | |
39 = Boolean.valueOf(getVMOption("BackgroundCompilation", "true")); | |
38 | 40 |
39 protected static Method getMethod(String name) { | 41 protected static Method getMethod(String name) { |
40 try { | 42 try { |
41 return CompilerWhiteBoxTest.class.getDeclaredMethod(name); | 43 return CompilerWhiteBoxTest.class.getDeclaredMethod(name); |
42 } catch (NoSuchMethodException | SecurityException e) { | 44 } catch (NoSuchMethodException | SecurityException e) { |
43 throw new RuntimeException( | 45 throw new RuntimeException( |
44 "exception on getting method " + name, e); | 46 "exception on getting method " + name, e); |
45 } | 47 } |
46 } | 48 } |
47 | 49 |
48 protected static String getVMOption(String name, String defaultValue) { | 50 protected static String getVMOption(String name) { |
49 String result; | 51 String result; |
50 HotSpotDiagnosticMXBean diagnostic | 52 HotSpotDiagnosticMXBean diagnostic |
51 = ManagementFactoryHelper.getDiagnosticMXBean(); | 53 = ManagementFactoryHelper.getDiagnosticMXBean(); |
52 result = diagnostic.getVMOption(name).getValue(); | 54 result = diagnostic.getVMOption(name).getValue(); |
55 return result; | |
56 } | |
57 | |
58 protected static String getVMOption(String name, String defaultValue) { | |
59 String result = getVMOption(name); | |
53 return result == null ? defaultValue : result; | 60 return result == null ? defaultValue : result; |
54 } | 61 } |
55 | 62 |
56 protected final void runTest() throws RuntimeException { | 63 protected final void runTest() throws RuntimeException { |
57 if (ManagementFactoryHelper.getCompilationMXBean() == null) { | 64 if (ManagementFactoryHelper.getCompilationMXBean() == null) { |
64 try { | 71 try { |
65 test(); | 72 test(); |
66 } catch (Exception e) { | 73 } catch (Exception e) { |
67 System.out.printf("on exception '%s':", e.getMessage()); | 74 System.out.printf("on exception '%s':", e.getMessage()); |
68 printInfo(METHOD); | 75 printInfo(METHOD); |
76 e.printStackTrace(); | |
69 throw new RuntimeException(e); | 77 throw new RuntimeException(e); |
70 } | 78 } |
71 System.out.println("at test's end:"); | 79 System.out.println("at test's end:"); |
72 printInfo(METHOD); | 80 printInfo(METHOD); |
73 } | 81 } |
98 } | 106 } |
99 } | 107 } |
100 | 108 |
101 protected static void waitBackgroundCompilation(Method method) | 109 protected static void waitBackgroundCompilation(Method method) |
102 throws InterruptedException { | 110 throws InterruptedException { |
111 if (!BACKGROUND_COMPILATION) { | |
112 return; | |
113 } | |
103 final Object obj = new Object(); | 114 final Object obj = new Object(); |
104 synchronized (obj) { | 115 synchronized (obj) { |
105 for (int i = 0; i < 10; ++i) { | 116 for (int i = 0; i < 10; ++i) { |
106 if (!WHITE_BOX.isMethodQueuedForCompilation(method)) { | 117 if (!WHITE_BOX.isMethodQueuedForCompilation(method)) { |
107 break; | 118 break; |
127 | 138 |
128 protected abstract void test() throws Exception; | 139 protected abstract void test() throws Exception; |
129 | 140 |
130 protected final int compile() { | 141 protected final int compile() { |
131 int result = 0; | 142 int result = 0; |
132 for (int i = 0; i < COMPILE_THRESHOLD; ++i) { | 143 int count = Math.max(COMPILE_THRESHOLD, 150000); |
144 for (int i = 0; i < count; ++i) { | |
133 result += method(); | 145 result += method(); |
134 } | 146 } |
147 System.out.println("method was invoked " + count + " times"); | |
135 return result; | 148 return result; |
136 } | 149 } |
137 | |
138 | 150 |
139 protected int method() { | 151 protected int method() { |
140 return 42; | 152 return 42; |
141 } | 153 } |
142 } | 154 } |