1 /* 2 * Copyright (C) 2016 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 package art; 18 19 import java.util.Arrays; 20 import java.util.Collections; 21 import java.util.HashSet; 22 23 public class Test907 { run()24 public static void run() throws Exception { 25 doTest(); 26 } 27 28 static final String NOT_A_REAL_CLASS = "art.NotARealClass_Foo_Bar_Baz"; 29 doTest()30 public static void doTest() throws Exception { 31 // Ensure some classes are loaded. 32 A a = new A(); 33 B b = new B(); 34 A[] aArray = new A[5]; 35 int[] iArray = new int[4]; 36 Object c; 37 Object d; 38 try { 39 // Cerr throws in it's clinit. 40 c = new Cerr(); 41 } catch (Error e) { } 42 try { 43 d = Class.forName(NOT_A_REAL_CLASS).getDeclaredConstructor().newInstance(); 44 } catch (Exception e) {} 45 46 String[] classes = getLoadedClasses(); 47 HashSet<String> classesSet = new HashSet<>(Arrays.asList(classes)); 48 49 String[] shouldBeLoaded = new String[] { 50 "java.lang.Object", "java.lang.Class", "java.lang.String", "art.Test907$A", 51 "art.Test907$B", "[Lart.Test907$A;", "[I", "art.Cerr", 52 }; 53 String[] shouldNotBeLoaded = new String[] { 54 "I", "J", "B", "Z", "V", "J", "F", "D", "C", "S", NOT_A_REAL_CLASS, 55 }; 56 57 boolean error = false; 58 for (String s : shouldNotBeLoaded) { 59 if (classesSet.contains(s)) { 60 System.out.println("Found" + s); 61 error = true; 62 } 63 } 64 for (String s : shouldBeLoaded) { 65 if (!classesSet.contains(s)) { 66 System.out.println("Did not find " + s); 67 error = true; 68 } 69 } 70 71 if (error) { 72 System.out.println(Arrays.toString(classes)); 73 } 74 } 75 76 static class A { 77 } 78 79 static class B { 80 } 81 getLoadedClasses()82 private static native String[] getLoadedClasses(); 83 } 84