test/hotspot/jtreg/runtime/appcds/SharedArchiveConsistency.java
changeset 51477 e77d7687c831
parent 48791 6e079ff6c83c
child 54838 d7819bedfaaf
equal deleted inserted replaced
51476:6c0ac4b4d761 51477:e77d7687c831
     1 /*
     1 /*
     2  * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    60 import sun.hotspot.WhiteBox;
    60 import sun.hotspot.WhiteBox;
    61 
    61 
    62 public class SharedArchiveConsistency {
    62 public class SharedArchiveConsistency {
    63     public static WhiteBox wb;
    63     public static WhiteBox wb;
    64     public static int offset_magic;    // FileMapHeader::_magic
    64     public static int offset_magic;    // FileMapHeader::_magic
    65     public static int sp_offset_crc;   // FileMapHeader::space_info::_crc
    65     public static int sp_offset_crc;   // CDSFileMapRegion::_crc
    66     public static int file_header_size = -1;// total size of header, variant, need calculation
    66     public static int file_header_size = -1;// total size of header, variant, need calculation
    67     public static int space_info_size; // size of space_info
    67     public static int CDSFileMapRegion_size; // size of CDSFileMapRegion
    68     public static int sp_offset;       // offset of FileMapHeader::space_info
    68     public static int sp_offset;       // offset of CDSFileMapRegion
    69     public static int sp_used_offset;  // offset of space_info::_used
    69     public static int sp_used_offset;  // offset of CDSFileMapRegion::_used
    70     public static int size_t_size;     // size of size_t
    70     public static int size_t_size;     // size of size_t
    71 
    71 
    72     public static File jsa;        // will be updated during test
    72     public static File jsa;        // will be updated during test
    73     public static File orgJsaFile; // kept the original file not touched.
    73     public static File orgJsaFile; // kept the original file not touched.
    74     public static String[] shared_region_name = {"MiscCode", "ReadWrite", "ReadOnly", "MiscData"};
    74     public static String[] shared_region_name = {"MiscCode", "ReadWrite", "ReadOnly", "MiscData"};
    81     };
    81     };
    82 
    82 
    83     public static void getFileOffsetInfo() throws Exception {
    83     public static void getFileOffsetInfo() throws Exception {
    84         wb = WhiteBox.getWhiteBox();
    84         wb = WhiteBox.getWhiteBox();
    85         offset_magic = wb.getOffsetForName("FileMapHeader::_magic");
    85         offset_magic = wb.getOffsetForName("FileMapHeader::_magic");
    86         sp_offset_crc = wb.getOffsetForName("space_info::_crc");
    86         sp_offset_crc = wb.getOffsetForName("CDSFileMapRegion::_crc");
    87         try {
    87         try {
    88             int nonExistOffset = wb.getOffsetForName("FileMapHeader::_non_exist_offset");
    88             int nonExistOffset = wb.getOffsetForName("FileMapHeader::_non_exist_offset");
    89             System.exit(-1); // should fail
    89             System.exit(-1); // should fail
    90         } catch (Exception e) {
    90         } catch (Exception e) {
    91             // success
    91             // success
    92         }
    92         }
    93 
    93 
    94         sp_offset = wb.getOffsetForName("FileMapHeader::_space[0]") - offset_magic;
    94         sp_offset = wb.getOffsetForName("FileMapHeader::_space[0]") - offset_magic;
    95         sp_used_offset = wb.getOffsetForName("space_info::_used") - sp_offset_crc;
    95         sp_used_offset = wb.getOffsetForName("CDSFileMapRegion::_used") - sp_offset_crc;
    96         size_t_size = wb.getOffsetForName("size_t_size");
    96         size_t_size = wb.getOffsetForName("size_t_size");
    97         space_info_size  = wb.getOffsetForName("space_info_size");
    97         CDSFileMapRegion_size  = wb.getOffsetForName("CDSFileMapRegion_size");
    98     }
    98     }
    99 
    99 
   100     public static int getFileHeaderSize(FileChannel fc) throws Exception {
   100     public static int getFileHeaderSize(FileChannel fc) throws Exception {
   101         if (file_header_size != -1) {
   101         if (file_header_size != -1) {
   102             return file_header_size;
   102             return file_header_size;
   164 
   164 
   165         int bufSize;
   165         int bufSize;
   166         System.out.printf("%-12s%-12s%-12s%-12s%-12s\n", "Space Name", "Offset", "Used bytes", "Reg Start", "Random Offset");
   166         System.out.printf("%-12s%-12s%-12s%-12s%-12s\n", "Space Name", "Offset", "Used bytes", "Reg Start", "Random Offset");
   167         start0 = getFileHeaderSize(fc);
   167         start0 = getFileHeaderSize(fc);
   168         for (int i = 0; i < num_regions; i++) {
   168         for (int i = 0; i < num_regions; i++) {
   169             used_offset = sp_offset + space_info_size * i + sp_used_offset;
   169             used_offset = sp_offset + CDSFileMapRegion_size * i + sp_used_offset;
   170             // read 'used'
   170             // read 'used'
   171             used[i] = readInt(fc, used_offset, size_t_size);
   171             used[i] = readInt(fc, used_offset, size_t_size);
   172             start = start0;
   172             start = start0;
   173             for (int j = 0; j < i; j++) {
   173             for (int j = 0; j < i; j++) {
   174                 start += align_up_page(used[j]);
   174                 start += align_up_page(used[j]);
   197         long total = 0L;
   197         long total = 0L;
   198         long used_offset = 0L;
   198         long used_offset = 0L;
   199         long[] used = new long[num_regions];
   199         long[] used = new long[num_regions];
   200         System.out.printf("%-12s%-12s\n", "Space name", "Used bytes");
   200         System.out.printf("%-12s%-12s\n", "Space name", "Used bytes");
   201         for (int i = 0; i < num_regions; i++) {
   201         for (int i = 0; i < num_regions; i++) {
   202             used_offset = sp_offset + space_info_size* i + sp_used_offset;
   202             used_offset = sp_offset + CDSFileMapRegion_size* i + sp_used_offset;
   203             // read 'used'
   203             // read 'used'
   204             used[i] = readInt(fc, used_offset, size_t_size);
   204             used[i] = readInt(fc, used_offset, size_t_size);
   205             System.out.printf("%-12s%-12d\n", shared_region_name[i], used[i]);
   205             System.out.printf("%-12s%-12d\n", shared_region_name[i], used[i]);
   206             total += used[i];
   206             total += used[i];
   207         }
   207         }