1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 public class MostDerived extends Derived {
test(Class main)18     public static void test(Class main) {
19         // The defining class loader of MostDerived (MDCL) is also the initiating loader of
20         // superclass Derived but delegates the loading to its parent class loader (PCL) which
21         // defines both Derived and Base. Thus Derived.class is recorded in MDCL's ClassTable
22         // but the Base.class is not because the Base's initiating loader is PCL. This is the
23         // case when loading the MostDerived class and remains the case after resolving the
24         // "invoke-super Derived.foo(.)" called from from MostDerived.foo(.). When that
25         // invoke-super is executed from AOT-compiled code, it goes through the .bss ArtMethod*
26         // entry and on first execution goes through the resolution method. After resolving to
27         // the Base.foo(.), the artQuickResolutionTrampoline() used to erroneously fill the
28         // Base.foo(.) entry in the MostDerived's DexCache which is wrong as the referenced
29         // class Base is not in the associated, i.e. MDCL's, ClassTable.
30         new MostDerived().foo(main);
31         try {
32             // This discrepancy then used to crash when resolving the Base.foo(.) method
33             // for JIT compilation of another method.
34             main.getDeclaredMethod("ensureJitCompiled", Class.class, String.class).invoke(
35                     null, MostDerived.class, "bar");
36         } catch (Throwable t) {
37             t.printStackTrace(System.out);
38         }
39         System.out.println("MostDerived.test(.) done.");
40     }
41 
foo(Class main)42     public void foo(Class main) {
43         super.foo(main);
44     }
45 
bar(Class main)46     public void bar(Class main) {
47         Base b = this;
48         b.foo(main);
49     }
50 }
51