1 /* 2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 25 /* 26 * @test ClassInitializationTest 27 * @bug 8142976 28 * @modules java.base/jdk.internal.misc 29 * @library /testlibrary 30 * @compile BadMap50.jasm 31 * @build jdk.test.lib.OutputAnalyzer jdk.test.lib.Platform jdk.test.lib.ProcessTools 32 * @run driver ClassInitializationTest 33 */ 34 35 import jdk.test.lib.OutputAnalyzer; 36 import jdk.test.lib.Platform; 37 import jdk.test.lib.ProcessTools; 38 39 public class ClassInitializationTest { 40 41 public static void main(String... args) throws Exception { 42 43 // (1) 44 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:class+init=info", 45 "-Xverify:all", 46 "-Xmx64m", 47 "BadMap50"); 48 OutputAnalyzer out = new OutputAnalyzer(pb.start()); 49 out.shouldContain("Start class verification for:"); 50 out.shouldContain("End class verification for:"); 51 out.shouldContain("Initializing"); 52 out.shouldContain("Verification for BadMap50 failed"); 53 out.shouldContain("Fail over class verification to old verifier for: BadMap50"); 54 55 // (2) 56 if (Platform.isDebugBuild()) { 57 pb = ProcessTools.createJavaProcessBuilder("-Xlog:class+init=info", 58 "-Xverify:all", 59 "-XX:+EagerInitialization", 60 "-Xmx64m", 61 InnerClass.class.getName()); 62 out = new OutputAnalyzer(pb.start()); 63 out.shouldContain("[Initialized").shouldContain("without side effects]"); 64 out.shouldHaveExitValue(0); 65 } 66 67 // (3) class+init should turn off. 68 pb = ProcessTools.createJavaProcessBuilder("-Xlog:class+init=off", 69 "-Xverify:all", 70 "-Xmx64m", 71 "BadMap50"); 72 out = new OutputAnalyzer(pb.start()); 73 out.shouldNotContain("[class,init]"); 74 out.shouldNotContain("Fail over class verification to old verifier for: BadMap50"); 75 76 } 77 public static class InnerClass { 78 public static void main(String[] args) throws Exception { 79 System.out.println("Inner Class"); 80 } 81 } 82 }