39 */
40
41 package compiler.exceptions;
42
43 import java.lang.reflect.Method;
44 import java.util.HashMap;
45
46 import jdk.test.lib.Asserts;
47 import jdk.test.whitebox.WhiteBox;
48
49 public class OptimizeImplicitExceptions {
50 // ImplicitException represents the various implicit (aka. 'built-in') exceptions
51 // which can be thrown implicitely by the JVM when executing bytecodes.
52 public enum ImplicitException {
53 // NullPointerException during field access
54 NULL_POINTER_EXCEPTION("null_check"),
55 // NullPointerException during invoke
56 INVOKE_NULL_POINTER_EXCEPTION("null_check"),
57 ARITHMETIC_EXCEPTION("div0_check"),
58 ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION("range_check"),
59 ARRAY_STORE_EXCEPTION("array_check"),
60 CLASS_CAST_EXCEPTION("class_check");
61 private final String reason;
62 ImplicitException(String reason) {
63 this.reason = reason;
64 }
65 public String getReason() {
66 return reason;
67 }
68 }
69 // TestMode represents a specific combination of the OmitStackTraceInFastThrow command line options.
70 // They will be set up in 'setFlags(TestMode testMode)' before a new test run starts.
71 public enum TestMode {
72 OMIT_STACKTRACES_IN_FASTTHROW,
73 STACKTRACES_IN_FASTTHROW
74 }
75
76 private static final WhiteBox WB = WhiteBox.getWhiteBox();
77 // The number of deoptimizations after which a method will be made not-entrant
78 private static final int PerBytecodeTrapLimit = WB.getIntxVMFlag("PerBytecodeTrapLimit").intValue();
79 // The number of interpreter invocations after which a decompiled method will be re-compiled.
85 private static String[] string_a = new String[1];
86 private static final Object o = new Object();
87
88 // This is the main test method. It will repeatedly called with the same ImplicitException 'type' to
89 // JIT-compile it, deoptimized it, re-compile it again and do various checks on the way.
90 // This process will be repeated then for each kind of ImplicitException 'type'.
91 public static Object throwImplicitException(ImplicitException type, Object[] object_a) {
92 switch (type) {
93 case NULL_POINTER_EXCEPTION: {
94 return object_a.length;
95 }
96 case INVOKE_NULL_POINTER_EXCEPTION: {
97 return object_a.hashCode();
98 }
99 case ARITHMETIC_EXCEPTION: {
100 return ((42 / (object_a.length - 1)) > 2) ? null : object_a[0];
101 }
102 case ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION: {
103 return object_a[5];
104 }
105 case ARRAY_STORE_EXCEPTION: {
106 return (object_a[0] = o);
107 }
108 case CLASS_CAST_EXCEPTION: {
109 return (ImplicitException[])object_a;
110 }
111 }
112 return null;
113 }
114
115 // Completely unload (i.e. make "not-entrant"->free) a JIT-compiled
116 // version of a method and clear the method's profiling counters.
117 private static void unloadAndClean(Method m) {
118 WB.deoptimizeMethod(m); // Makes the nmethod "not entrant".
119 System.gc();
120 WB.clearMethodState(m);
121 }
122
123 // Set '-XX' flags according to 'TestMode'
124 private static void setFlags(TestMode testMode) {
125 if (testMode == TestMode.OMIT_STACKTRACES_IN_FASTTHROW) {
126 WB.setBooleanVMFlag("OmitStackTraceInFastThrow", true);
127 } else {
|
39 */
40
41 package compiler.exceptions;
42
43 import java.lang.reflect.Method;
44 import java.util.HashMap;
45
46 import jdk.test.lib.Asserts;
47 import jdk.test.whitebox.WhiteBox;
48
49 public class OptimizeImplicitExceptions {
50 // ImplicitException represents the various implicit (aka. 'built-in') exceptions
51 // which can be thrown implicitely by the JVM when executing bytecodes.
52 public enum ImplicitException {
53 // NullPointerException during field access
54 NULL_POINTER_EXCEPTION("null_check"),
55 // NullPointerException during invoke
56 INVOKE_NULL_POINTER_EXCEPTION("null_check"),
57 ARITHMETIC_EXCEPTION("div0_check"),
58 ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION("range_check"),
59 // TODO 8366668 This currently fails
60 // ARRAY_STORE_EXCEPTION("array_check"),
61 CLASS_CAST_EXCEPTION("class_check");
62 private final String reason;
63 ImplicitException(String reason) {
64 this.reason = reason;
65 }
66 public String getReason() {
67 return reason;
68 }
69 }
70 // TestMode represents a specific combination of the OmitStackTraceInFastThrow command line options.
71 // They will be set up in 'setFlags(TestMode testMode)' before a new test run starts.
72 public enum TestMode {
73 OMIT_STACKTRACES_IN_FASTTHROW,
74 STACKTRACES_IN_FASTTHROW
75 }
76
77 private static final WhiteBox WB = WhiteBox.getWhiteBox();
78 // The number of deoptimizations after which a method will be made not-entrant
79 private static final int PerBytecodeTrapLimit = WB.getIntxVMFlag("PerBytecodeTrapLimit").intValue();
80 // The number of interpreter invocations after which a decompiled method will be re-compiled.
86 private static String[] string_a = new String[1];
87 private static final Object o = new Object();
88
89 // This is the main test method. It will repeatedly called with the same ImplicitException 'type' to
90 // JIT-compile it, deoptimized it, re-compile it again and do various checks on the way.
91 // This process will be repeated then for each kind of ImplicitException 'type'.
92 public static Object throwImplicitException(ImplicitException type, Object[] object_a) {
93 switch (type) {
94 case NULL_POINTER_EXCEPTION: {
95 return object_a.length;
96 }
97 case INVOKE_NULL_POINTER_EXCEPTION: {
98 return object_a.hashCode();
99 }
100 case ARITHMETIC_EXCEPTION: {
101 return ((42 / (object_a.length - 1)) > 2) ? null : object_a[0];
102 }
103 case ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION: {
104 return object_a[5];
105 }
106 // TODO 8366668 Re-enable
107 /*
108 case ARRAY_STORE_EXCEPTION: {
109 return (object_a[0] = o);
110 }
111 */
112 case CLASS_CAST_EXCEPTION: {
113 return (ImplicitException[])object_a;
114 }
115 }
116 return null;
117 }
118
119 // Completely unload (i.e. make "not-entrant"->free) a JIT-compiled
120 // version of a method and clear the method's profiling counters.
121 private static void unloadAndClean(Method m) {
122 WB.deoptimizeMethod(m); // Makes the nmethod "not entrant".
123 System.gc();
124 WB.clearMethodState(m);
125 }
126
127 // Set '-XX' flags according to 'TestMode'
128 private static void setFlags(TestMode testMode) {
129 if (testMode == TestMode.OMIT_STACKTRACES_IN_FASTTHROW) {
130 WB.setBooleanVMFlag("OmitStackTraceInFastThrow", true);
131 } else {
|