• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Main {
18     public static String TEST_NAME = "158-app-image-class-table";
19 
main(String[] args)20     public static void main(String[] args) {
21         try {
22             Class<?> class_loader_class = Class.forName("dalvik.system.PathClassLoader");
23             System.loadLibrary(args[0]);
24         } catch (ClassNotFoundException e) {
25             usingRI = true;
26             // Add expected JNI_OnLoad log line to match expected-stdout.txt.
27             System.out.println("JNI_OnLoad called");
28         }
29         try {
30             // Resolve but do not initialize TestImplementation. During the resolution,
31             // we see the Cloneable in the dex cache, so we do not try to look it up
32             // or resolve it.
33             Class<?> timpl =
34                 Class.forName("TestImplementation", false, Main.class.getClassLoader());
35             // Clear the dex cache resolved types to force a proper lookup the next time
36             // we need to find TestInterface.
37             clearResolvedTypes(timpl);
38             // Force intialization of TestImplementation. This expects the interface type
39             // to be resolved and found through simple lookup.
40             timpl.newInstance();
41         } catch (Throwable t) {
42             t.printStackTrace(System.out);
43         }
44     }
45 
clearResolvedTypes(Class<?> c)46     public static void clearResolvedTypes(Class<?> c) {
47         if (!usingRI) {
48             nativeClearResolvedTypes(c);
49         }
50     }
51 
52     private static boolean usingRI = false;
53 
nativeClearResolvedTypes(Class<?> c)54     public static native void nativeClearResolvedTypes(Class<?> c);
55 }
56