/* * Copyright (c) 2013, 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.
*/
privatestaticint runFoo() throws Throwable {
assertEquals(Init1Tick, 0); // Init1 not initialized yet int t1 = tick("runFoo"); int t2 = (int) INDY_foo().invokeExact(); int t3 = tick("runFoo done");
assertEquals(Init1Tick, t2); // when Init1 was initialized
assertEquals(t1+2, t3); // exactly two ticks in between
assertEquals(t1+1, t2); // init happened inside return t2;
} privatestatic MethodHandle INDY_foo() throws Throwable {
shouldNotCallThis(); return ((CallSite) MH_bsm().invoke(lookup(), "foo", methodType(int.class))).dynamicInvoker();
}
privatestaticint runBar() throws Throwable {
assertEquals(Init2Tick, 0); // Init2 not initialized yet int t1 = tick("runBar"); int t2 = (int) INDY_bar().invokeExact(); int t3 = tick("runBar done");
assertEquals(Init2Tick, t2); // when Init2 was initialized
assertEquals(t1+2, t3); // exactly two ticks in between
assertEquals(t1+1, t2); // init happened inside return t2;
} privatestatic MethodHandle INDY_bar() throws Throwable {
shouldNotCallThis(); return ((CallSite) MH_bsm().invoke(lookup(), "bar", methodType(int.class))).dynamicInvoker();
}
privatestaticint runBaz() throws Throwable {
assertEquals(Init3Tick, 0); // Init3 not initialized yet int t1 = tick("runBaz"); int t2 = (int) INDY_baz().invokeExact(); int t3 = tick("runBaz done");
assertEquals(Init3Tick, t2); // when Init3 was initialized
assertEquals(t1+2, t3); // exactly two ticks in between
assertEquals(t1+1, t2); // init happened inside return t2;
} privatestatic MethodHandle INDY_baz() throws Throwable {
shouldNotCallThis(); return ((CallSite) MH_bsm().invoke(lookup(), "baz", methodType(int.class))).dynamicInvoker();
}
privatestaticint runBat() throws Throwable {
assertEquals(Init4Tick, 0); // Init4 not initialized yet int t1 = tick("runBat"); int t2 = (int) INDY_bat().invokeExact(); int t3 = tick("runBat done");
assertEquals(Init4Tick, t2); // when Init4 was initialized
assertEquals(t1+2, t3); // exactly two ticks in between
assertEquals(t1+1, t2); // init happened inside return t2;
} privatestatic MethodHandle INDY_bat() throws Throwable {
shouldNotCallThis(); return ((CallSite) MH_bsm().invoke(lookup(), "bat", methodType(int.class))).dynamicInvoker();
}
privatestaticint runBang() throws Throwable {
assertEquals(Init5Tick, 0); // Init5 not initialized yet int t1 = tick("runBang"); int t2 = (int) INDY_bang().invokeExact(); int t3 = tick("runBang done");
assertEquals(Init5Tick, t2); // when Init5 was initialized
assertEquals(t1+2, t3); // exactly two ticks in between
assertEquals(t1+1, t2); // init happened inside return t2;
} privatestatic MethodHandle INDY_bang() throws Throwable {
shouldNotCallThis(); return ((CallSite) MH_bsm().invoke(lookup(), "bang", methodType(int.class))).dynamicInvoker();
}
privatestaticint runPong() throws Throwable {
assertEquals(Init6Tick, 0); // Init6 not initialized yet int t1 = tick("runPong"); int t2 = (int) INDY_pong().invokeExact(); int t3 = tick("runPong done");
assertEquals(Init6Tick, t2); // when Init6 was initialized
assertEquals(t1+2, t3); // exactly two ticks in between
assertEquals(t1+1, t2); // init happened inside return t2;
} privatestatic MethodHandle INDY_pong() throws Throwable {
shouldNotCallThis(); return ((CallSite) MH_bsm().invoke(lookup(), "pong", methodType(int.class))).dynamicInvoker();
}
privatestatic CallSite bsm(Lookup caller, String name, MethodType type) throws ReflectiveOperationException {
System.out.println("bsm "+name+type);
CallSite res; switch (name) { case"foo":
res = new ConstantCallSite(MH_foo()); break; case"bar":
res = new ConstantCallSite(CONSTANT_MH_bar); break; case"baz":
res = CONSTANT_CS_baz; break; case"bat":
res = new ConstantCallSite(CONSTANT_MH_bat); break; case"bang":
res = new ConstantCallSite(CONSTANT_MH_bangGetter); break; case"pong":
res = new ConstantCallSite(CONSTANT_MH_pongSetter); break; default:
res = null;
} if (res == null || !res.type().equals(type)) { thrownew AssertionError(String.valueOf(res));
} return res;
} privatestatic MethodHandle MH_bsm() throws ReflectiveOperationException {
shouldNotCallThis(); return lookup().findStatic(lookup().lookupClass(), "bsm",
methodType(CallSite.class, Lookup.class, String.class, MethodType.class));
} privatestaticvoid shouldNotCallThis() { // if this gets called, the transformation has not taken place thrownew AssertionError("this code should be statically transformed away by Indify");
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.12 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.