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 import libcore.util.EmptyArray; 18 19 public class Main { main(String[] args)20 public static void main(String[] args) { 21 try { 22 // Check if we're running dalvik or RI. 23 Class<?> class_loader_class = Class.forName("dalvik.system.PathClassLoader"); 24 System.loadLibrary(args[0]); 25 } catch (ClassNotFoundException e) { 26 usingRI = true; 27 // Add expected JNI_OnLoad log line to match expected.txt. 28 System.out.println("JNI_OnLoad called"); 29 } 30 try { 31 // Initialize all classes needed for old java.lang.Void.TYPE initialization. 32 Runnable.class.getMethod("run", EmptyArray.CLASS).getReturnType(); 33 } catch (Exception e) { 34 throw new Error(e); 35 } 36 // Clear the resolved types of the ojluni dex file to make sure there is no entry 37 // for "V", i.e. void. 38 clearResolvedTypes(Integer.class); 39 // With java.lang.Void being compile-time verified but uninitialized, initialize 40 // it now. Previously, this would indirectly initialize TYPE with the current, 41 // i.e. zero-initialized, value of TYPE. The only thing that could prevent the 42 // series of calls leading to this was a cache hit in Class.getDexCacheType() 43 // which we have prevented by clearing the cache above. 44 Class<?> voidClass = void.class; 45 System.out.println("void.class = " + voidClass); 46 } 47 clearResolvedTypes(Class<?> c)48 public static void clearResolvedTypes(Class<?> c) { 49 if (!usingRI) { 50 nativeClearResolvedTypes(c); 51 } 52 } 53 nativeClearResolvedTypes(Class<?> c)54 public static native void nativeClearResolvedTypes(Class<?> c); 55 56 static boolean usingRI = false; 57 } 58