1 /* 2 * Copyright (c) 2018, 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 import java.io.File; 26 import java.lang.module.ModuleDescriptor; 27 import java.util.Set; 28 import sun.hotspot.WhiteBox; 29 30 // 31 // Test archived system module graph when open archive heap objects are mapped: 32 // 33 public class CheckArchivedModuleApp { 34 static WhiteBox wb; 35 public static void main(String args[]) throws Exception { 36 wb = WhiteBox.getWhiteBox(); 37 38 if (!wb.areOpenArchiveHeapObjectsMapped()) { 39 System.out.println("Archived open_archive_heap objects are not mapped."); 40 System.out.println("This may happen during normal operation. Test Skipped."); 41 return; 42 } 43 44 boolean expectArchived = "yes".equals(args[0]); 45 checkModuleDescriptors(expectArchived); 46 } 47 48 private static void checkModuleDescriptors(boolean expectArchived) { 49 Set<Module> modules = ModuleLayer.boot().modules(); 50 for (Module m : modules) { 51 ModuleDescriptor md = m.getDescriptor(); 52 String name = md.name(); 53 if (expectArchived) { 54 if (wb.isShared(md)) { 55 System.out.println(name + " is archived. Expected."); 56 } else { 57 throw new RuntimeException( 58 "FAILED. " + name + " is not archived. Expect archived."); 59 } 60 } else { 61 if (!wb.isShared(md)) { 62 System.out.println(name + " is not archived. Expected."); 63 } else { 64 throw new RuntimeException( 65 "FAILED. " + name + " is archived. Expect not archived."); 66 } 67 } 68 } 69 } 70 }