1 /* 2 * Copyright (C) 2024 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 import java.lang.reflect.Constructor; 18 import java.lang.reflect.Method; 19 20 public class Main { 21 static final String DEX_FILE = 22 System.getenv("DEX_LOCATION") + "/854-image-inlining-ex.jar"; 23 static final String LIBRARY_SEARCH_PATH = System.getProperty("java.library.path"); 24 main(String[] args)25 public static void main(String[] args) throws Exception { 26 // Create the secondary class loader. 27 Class<?> pathClassLoader = Class.forName("dalvik.system.PathClassLoader"); 28 Constructor<?> constructor = 29 pathClassLoader.getDeclaredConstructor(String.class, String.class, ClassLoader.class); 30 ClassLoader loader = (ClassLoader) constructor.newInstance( 31 DEX_FILE, LIBRARY_SEARCH_PATH, ClassLoader.getSystemClassLoader()); 32 33 // Invoke the test method to trigger the runtime crash. 34 Method m = loader.loadClass("Test").getDeclaredMethod("callInstance"); 35 int result = ((Integer) m.invoke(null)).intValue(); 36 if (result != 42) { 37 throw new Error("Expected 42, got " + result); 38 } 39 } 40 } 41