blob: 0a052e774d7993ef95ae020758e76d00e91ff9ea [file] [log] [blame]
Vladimir Markoe00e5592017-02-24 14:58:29 +00001/*
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
17import libcore.util.EmptyArray;
18
19public class Main {
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.
Vladimir Marko0b66d612017-03-13 14:50:04 +000038 // TODO: Enable clearing the dex cache when we switch to the hash-based type array
39 // and do a proper lookup. Currently, ClassLinker fully relies on the DexCache.
40 if (false) {
41 clearResolvedTypes(Integer.class);
42 }
Vladimir Markoe00e5592017-02-24 14:58:29 +000043 // With java.lang.Void being compile-time verified but uninitialized, initialize
44 // it now. Previously, this would indirectly initialize TYPE with the current,
45 // i.e. zero-initialized, value of TYPE. The only thing that could prevent the
46 // series of calls leading to this was a cache hit in Class.getDexCacheType()
47 // which we have prevented by clearing the cache above.
48 Class<?> voidClass = void.class;
49 System.out.println("void.class = " + voidClass);
50 }
51
52 public static void clearResolvedTypes(Class<?> c) {
53 if (!usingRI) {
54 nativeClearResolvedTypes(c);
55 }
56 }
57
58 public static native void nativeClearResolvedTypes(Class<?> c);
59
60 static boolean usingRI = false;
61}