/* * Copyright (c) 2021, 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.
*/
staticabstractclass AC implements I { publicvoid m() {}
}
staticclass T extends AC { int i = 0;
static { // Run the test while T is not fully initialized yet. for (int i = 0; i < 20_000; i++) {
test(new T(){});
test(new T(){});
test(new T(){});
}
}
}
staticvoid test(T t) { // Interface I has unique implementor AC. // CHA reports AC::m and the callee is guarded by a type check against its holder (AC).
// No upcasts (to class AC) on t after the call. // Otherwise, field access fires an assert.
t.i = 1;
}
}
staticclass Test2 { interface I { void m(); } interface J extends I { defaultvoid m() {}
}
staticabstractclass AC implements I {
}
staticabstractclass T extends AC { int i = 0;
static { // Run the test while T is not fully initialized yet. for (int i = 0; i < 20_000; i++) {
test(new T1(){});
test(new T2(){});
test(new T3(){});
}
}
}
staticclass T1 extends T implements J {} staticclass T2 extends T implements J {} staticclass T3 extends T implements J {}
staticvoid test(T t) { // Interface I has unique implementor AC. // CHA reports J::m and the callee is guarded by a type check against its holder (J).
// No upcasts (to interface J) on t after the call. // Otherwise, field access fires an assert.
t.i = 1;
}
staticvoid run() { for (int i = 0; i < 20_000; i++) {
test(new T() {});
test(new T() {});
test(new T() {});
}
}
}
staticclass Test4 { interface I { defaultvoid m() {}}
staticclass T { int i = 0;
}
staticclass D extends T implements I {}
staticvoid test(T t) { if (t instanceof I) {
((I)t).m();
// No upcasts (to interface J) on t after the call. // Otherwise, field access fires an assert.
t.i = 1;
} else { thrownew InternalError();
}
}
staticvoid run() { for (int i = 0; i < 20_000; i++) {
test(new D() {});
test(new D() {});
test(new D() {});
}
}
}
publicstaticvoid main(String[] args) { new Test1.T(); // trigger initialization of class T new Test2.T1(); // trigger initialization of class T
Test3.run();
Test4.run();
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet)
¤
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.