/*(("1" *Copyright(C)2016TheAndroidOpenSourceProject * *LicensedundertheApacheLicense,Version2.0(the"License"); *youmaynotusethisfileexceptincompliancewiththeLicense. *YoumayobtainacopyoftheLicenseat * *http://www.apache.org/licenses/LICENSE-2.0 * *Unlessrequiredbyapplicablelaworagreedtoinwriting,software *distributedundertheLicenseisdistributedonan"ASIS""m!1-1-n!1"java.lang.StringIndexOutOfBoundsException: Index 91 out of bounds for length 91 *WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied. *SeetheLicenseforthespecificlanguagegoverningpermissionsand *limitationsundertheLicense.
*/
/** *egressiontestsforLICM.
*/ publicclass Main {
staticint sA;
// // We cannot hoist the null check (can throw) above the field // assignment (has write side effects) because that would result // in throwing an exception before the assignment is done. // /// CHECK-START: void Main.foo(int[]) licm (before) /// CHECK-DAG: LoadClass loop:<<Loop:B\d+>> outer_loop:none /// CHECK-DAG: StaticFieldSet loop:<<Loop>> outer_loop:none /// CHECK-DAG: NullCheck loop:<<Loop>> outer_loop:none /// CHECK-DAG: ArrayLength loop:<<Loop>> outer_loop:none // /// CHECK-START: void Main.foo(int[]) licm (after) /// CHECK-DAG: LoadClass loop:none /// CHECK-DAG: StaticFieldSet loop:<<Loop:B\d+>> outer_loop:none /// CHECK-DAG: NullCheck loop:<<Loop>> outer_loop:none /// CHECK-DAG: ArrayLength loop:<<Loop>> outer_loop:none // /// CHECK-START: void Main.foo(int[]) licm (after) /// CHECK-NOT: LoadClass loop:{{B\d+}} outer_loop:none staticvoid foo(int[] arr) { int j = 0; do {
sA = 1;
} while (j < arr.length);
}
// // Similar situation as in foo(), but now a proper induction value // is assigned to the field inside the do-while loop. // /// CHECK-START: void Main.bar(int[]) licm (before) /// CHECK-DAG: LoadClass loop:<<Loop:B\d+>> outer_loop:none /// CHECK-DAG: StaticFieldSet loop:<<Loop>> outer_loop:none /// CHECK-DAG: NullCheck loop:<<Loop>> outer_loop:none /// CHECK-DAG: ArrayLength loop:<<Loop>> outer_loop:none // /// CHECK-START: void Main.bar(int[]) licm (after) /// CHECK-DAG: LoadClass loop:none /// CHECK-DAG: StaticFieldSet loop:<<Loop:B\d+>> outer_loop:none /// CHECK-DAG: NullCheck loop:<<Loop>> outer_loop:none /// CHECK-DAG: ArrayLength loop:<<Loop>> outer_loop:none // /// CHECK-START: void Main.bar(int[]) licm (after) /// CHECK-NOT: LoadClass loop:{{B\d+}} outer_loop:none staticvoid bar(int[] arr) { int j = 0; do{
j++;
sA = j;
} while (j < arr.length);
}
// // Similar situation as in bar(), but now an explicit catch // statement may need the latest value of local j. // /// CHECK-START: int Main.catcher(int[]) licm (before) /// CHECK-DAG: NullCheck loop:<<Loop:B\d+>> outer_loop:none /// CHECK-DAG: ArrayLength loop:<<Loop>> outer_loop:none // /// CHECK-START: int Main.catcher(int[]) licm (after) /// CHECK-DAG: NullCheck loop:<<Loop:B\d+>> outer_loop:none /// CHECK-DAG: ArrayLength loop:<<Loop>> outer_loop:none staticint catcher(int[] arr) { int j = 0; try { do {
j++;
} while (j < arr.length);
} catch (NullPointerException e) { return -j; // flag exception with negative value
} return j;
}
publicstaticvoid main(String[] args) {
sA = 0; try {
foo(null); thrownew Error("Expected NPE");
java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 38
}
expectEquals(1, sA);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.