hotspot/src/share/vm/classfile/imageFile.hpp
author jfdenise
Thu, 25 Jun 2015 18:25:19 +0200
changeset 31608 b5cb9a07591a
parent 27562 47f369e3c69c
permissions -rw-r--r--
8080511: Refresh of jimage support Reviewed-by: alanb, mchung, psandoz, acorn, lfoltan, ctornqvi Contributed-by: james.laskey@oracle.com, jean-francois.denise@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     1
/*
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     4
 *
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     8
 *
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    13
 * accompanied this code).
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    14
 *
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    18
 *
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    21
 * questions.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    22
 *
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    23
 */
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    24
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    25
#ifndef SHARE_VM_CLASSFILE_IMAGEFILE_HPP
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    26
#define SHARE_VM_CLASSFILE_IMAGEFILE_HPP
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    27
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    28
#include "classfile/classLoader.hpp"
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    29
#include "memory/allocation.hpp"
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    30
#include "memory/allocation.inline.hpp"
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    31
#include "utilities/endian.hpp"
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    32
#include "utilities/globalDefinitions.hpp"
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    33
#include "utilities/growableArray.hpp"
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    34
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    35
// Image files are an alternate file format for storing classes and resources. The
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    36
// goal is to supply file access which is faster and smaller than the jar format.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    37
// It should be noted that unlike jars, information stored in an image is in native
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    38
// endian format. This allows the image to be mapped into memory without endian
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    39
// translation.  This also means that images are platform dependent.
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    40
//
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    41
// Image files are structured as three sections;
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    42
//
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    43
//         +-----------+
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    44
//         |  Header   |
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    45
//         +-----------+
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    46
//         |           |
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    47
//         |   Index   |
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    48
//         |           |
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    49
//         +-----------+
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    50
//         |           |
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    51
//         |           |
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    52
//         | Resources |
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    53
//         |           |
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    54
//         |           |
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    55
//         +-----------+
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    56
//
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    57
// The header contains information related to identification and description of
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    58
// contents.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    59
//
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    60
//         +-------------------------+
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    61
//         |   Magic (0xCAFEDADA)    |
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    62
//         +------------+------------+
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    63
//         | Major Vers | Minor Vers |
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    64
//         +------------+------------+
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    65
//         |          Flags          |
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    66
//         +-------------------------+
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    67
//         |      Resource Count     |
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    68
//         +-------------------------+
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    69
//         |       Table Length      |
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    70
//         +-------------------------+
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    71
//         |      Attributes Size    |
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    72
//         +-------------------------+
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    73
//         |       Strings Size      |
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    74
//         +-------------------------+
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    75
//
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    76
// Magic - means of identifying validity of the file.  This avoids requiring a
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    77
//         special file extension.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    78
// Major vers, minor vers - differences in version numbers indicate structural
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    79
//                          changes in the image.
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    80
// Flags - various image wide flags (future).
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    81
// Resource count - number of resources in the file.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    82
// Table length - the length of lookup tables used in the index.
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    83
// Attributes size - number of bytes in the region used to store location attribute
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    84
//                   streams.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    85
// Strings size - the size of the region used to store strings used by the
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    86
//                index and meta data.
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    87
//
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    88
// The index contains information related to resource lookup. The algorithm
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    89
// used for lookup is "A Practical Minimal Perfect Hashing Method"
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    90
// (http://homepages.dcc.ufmg.br/~nivio/papers/wea05.pdf). Given a path string
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    91
// in the form /<module>/<package>/<base>.<extension>  return the resource location
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    92
// information;
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    93
//
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    94
//     redirectIndex = hash(path, DEFAULT_SEED) % table_length;
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    95
//     redirect = redirectTable[redirectIndex];
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    96
//     if (redirect == 0) return not found;
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
    97
//     locationIndex = redirect < 0 ? -1 - redirect : hash(path, redirect) % table_length;
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    98
//     location = locationTable[locationIndex];
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
    99
//     if (!verify(location, path)) return not found;
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   100
//     return location;
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   101
//
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   102
// Note: The hash function takes an initial seed value.  A different seed value
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   103
// usually returns a different result for strings that would otherwise collide with
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   104
// other seeds. The verify function guarantees the found resource location is
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   105
// indeed the resource we are looking for.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   106
//
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   107
// The following is the format of the index;
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   108
//
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   109
//         +-------------------+
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   110
//         |   Redirect Table  |
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   111
//         +-------------------+
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   112
//         | Attribute Offsets |
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   113
//         +-------------------+
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   114
//         |   Attribute Data  |
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   115
//         +-------------------+
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   116
//         |      Strings      |
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   117
//         +-------------------+
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   118
//
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   119
// Redirect Table - Array of 32-bit signed values representing actions that
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   120
//                  should take place for hashed strings that map to that
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   121
//                  value.  Negative values indicate no hash collision and can be
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   122
//                  quickly converted to indices into attribute offsets.  Positive
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   123
//                  values represent a new seed for hashing an index into attribute
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   124
//                  offsets.  Zero indicates not found.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   125
// Attribute Offsets - Array of 32-bit unsigned values representing offsets into
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   126
//                     attribute data.  Attribute offsets can be iterated to do a
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   127
//                     full survey of resources in the image.  Offset of zero
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   128
//                     indicates no attributes.
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   129
// Attribute Data - Bytes representing compact attribute data for locations. (See
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   130
//                  comments in ImageLocation.)
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   131
// Strings - Collection of zero terminated UTF-8 strings used by the index and
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   132
//           image meta data.  Each string is accessed by offset.  Each string is
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   133
//           unique.  Offset zero is reserved for the empty string.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   134
//
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   135
// Note that the memory mapped index assumes 32 bit alignment of each component
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   136
// in the index.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   137
//
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   138
// Endianness of an image.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   139
// An image booted by hotspot is always in native endian.  However, it is possible
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   140
// to read (by the JDK) in alternate endian format.  Primarily, this is during
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   141
// cross platform scenarios.  Ex, where javac needs to read an embedded image
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   142
// to access classes for crossing compilation.
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   143
//
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   144
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   145
class ImageFileReader; // forward declaration
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   146
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   147
// Manage image file string table.
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   148
class ImageStrings VALUE_OBJ_CLASS_SPEC {
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   149
private:
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   150
  u1* _data; // Data bytes for strings.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   151
  u4 _size; // Number of bytes in the string table.
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   152
public:
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   153
  enum {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   154
    // Not found result from find routine.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   155
    NOT_FOUND = -1,
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   156
    // Prime used to generate hash for Perfect Hashing.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   157
    HASH_MULTIPLIER = 0x01000193
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   158
  };
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   159
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   160
  ImageStrings(u1* data, u4 size) : _data(data), _size(size) {}
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   161
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   162
  // Return the UTF-8 string beginning at offset.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   163
  inline const char* get(u4 offset) const {
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   164
    guarantee(offset < _size, "offset exceeds string table size");
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   165
    return (const char*)(_data + offset);
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   166
  }
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   167
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   168
  // Compute the Perfect Hashing hash code for the supplied UTF-8 string.
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   169
  inline static u4 hash_code(const char* string) {
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   170
    return hash_code(string, HASH_MULTIPLIER);
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   171
  }
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   172
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   173
  // Compute the Perfect Hashing hash code for the supplied string, starting at seed.
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   174
  static s4 hash_code(const char* string, s4 seed);
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   175
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   176
  // Match up a string in a perfect hash table.  Result still needs validation
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   177
  // for precise match.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   178
  static s4 find(Endian* endian, const char* name, s4* redirect, u4 length);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   179
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   180
  // Test to see if UTF-8 string begins with the start UTF-8 string.  If so,
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   181
  // return non-NULL address of remaining portion of string.  Otherwise, return
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   182
  // NULL.  Used to test sections of a path without copying from image string
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   183
  // table.
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   184
  static const char* starts_with(const char* string, const char* start);
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   185
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   186
  // Test to see if UTF-8 string begins with start char.  If so, return non-NULL
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   187
  // address of remaining portion of string.  Otherwise, return NULL.  Used
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   188
  // to test a character of a path without copying.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   189
  inline static const char* starts_with(const char* string, const char ch) {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   190
    return *string == ch ? string + 1 : NULL;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   191
  }
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   192
};
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   193
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   194
// Manage image file location attribute data.  Within an image, a location's
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   195
// attributes are compressed into a stream of bytes.  An attribute stream is
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   196
// composed of individual attribute sequences.  Each attribute sequence begins with
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   197
// a header byte containing the attribute 'kind' (upper 5 bits of header) and the
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   198
// 'length' less 1 (lower 3 bits of header) of bytes that follow containing the
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   199
// attribute value.  Attribute values present as most significant byte first.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   200
//
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   201
// Ex. Container offset (ATTRIBUTE_OFFSET) 0x33562 would be represented as 0x22
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   202
// (kind = 4, length = 3), 0x03, 0x35, 0x62.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   203
//
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   204
// An attribute stream is terminated with a header kind of ATTRIBUTE_END (header
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   205
// byte of zero.)
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   206
//
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   207
// ImageLocation inflates the stream into individual values stored in the long
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   208
// array _attributes. This allows an attribute value can be quickly accessed by
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   209
// direct indexing. Unspecified values default to zero.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   210
//
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   211
// Notes:
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   212
//  - Even though ATTRIBUTE_END is used to mark the end of the attribute stream,
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   213
//    streams will contain zero byte values to represent lesser significant bits.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   214
//    Thus, detecting a zero byte is not sufficient to detect the end of an attribute
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   215
//    stream.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   216
//  - ATTRIBUTE_OFFSET represents the number of bytes from the beginning of the region
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   217
//    storing the resources.  Thus, in an image this represents the number of bytes
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   218
//    after the index.
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   219
//  - Currently, compressed resources are represented by having a non-zero
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   220
//    ATTRIBUTE_COMPRESSED value.  This represents the number of bytes stored in the
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   221
//    image, and the value of ATTRIBUTE_UNCOMPRESSED represents number of bytes of the
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   222
//    inflated resource in memory. If the ATTRIBUTE_COMPRESSED is zero then the value
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   223
//    of ATTRIBUTE_UNCOMPRESSED represents both the number of bytes in the image and
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   224
//    in memory.  In the future, additional compression techniques will be used and
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   225
//    represented differently.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   226
//  - Package strings include trailing slash and extensions include prefix period.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   227
//
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   228
class ImageLocation VALUE_OBJ_CLASS_SPEC {
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   229
public:
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   230
  enum {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   231
    ATTRIBUTE_END,          // End of attribute stream marker
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   232
    ATTRIBUTE_MODULE,       // String table offset of module name
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   233
    ATTRIBUTE_PARENT,       // String table offset of resource path parent
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   234
    ATTRIBUTE_BASE,         // String table offset of resource path base
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   235
    ATTRIBUTE_EXTENSION,    // String table offset of resource path extension
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   236
    ATTRIBUTE_OFFSET,       // Container byte offset of resource
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   237
    ATTRIBUTE_COMPRESSED,   // In image byte size of the compressed resource
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   238
    ATTRIBUTE_UNCOMPRESSED, // In memory byte size of the uncompressed resource
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   239
    ATTRIBUTE_COUNT         // Number of attribute kinds
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   240
  };
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   241
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   242
private:
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   243
  // Values of inflated attributes.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   244
  u8 _attributes[ATTRIBUTE_COUNT];
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   245
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   246
  // Return the attribute value number of bytes.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   247
  inline static u1 attribute_length(u1 data) {
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   248
    return (data & 0x7) + 1;
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   249
  }
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   250
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   251
  // Return the attribute kind.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   252
  inline static u1 attribute_kind(u1 data) {
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   253
    u1 kind = data >> 3;
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   254
    guarantee(kind < ATTRIBUTE_COUNT, "invalid attribute kind");
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   255
    return kind;
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   256
  }
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   257
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   258
  // Return the attribute length.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   259
  inline static u8 attribute_value(u1* data, u1 n) {
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   260
    guarantee(0 < n && n <= 8, "invalid attribute value length");
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   261
    u8 value = 0;
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   262
    // Most significant bytes first.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   263
    for (u1 i = 0; i < n; i++) {
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   264
      value <<= 8;
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   265
      value |= data[i];
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   266
    }
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   267
    return value;
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   268
  }
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   269
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   270
public:
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   271
  ImageLocation() {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   272
    clear_data();
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   273
  }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   274
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   275
  ImageLocation(u1* data) {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   276
    clear_data();
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   277
    set_data(data);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   278
  }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   279
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   280
  // Inflates the attribute stream into individual values stored in the long
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   281
  // array _attributes. This allows an attribute value to be quickly accessed by
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   282
  // direct indexing. Unspecified values default to zero.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   283
  void set_data(u1* data);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   284
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   285
  // Zero all attribute values.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   286
  void clear_data();
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   287
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   288
  // Retrieve an attribute value from the inflated array.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   289
  inline u8 get_attribute(u1 kind) const {
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   290
    guarantee(ATTRIBUTE_END < kind && kind < ATTRIBUTE_COUNT, "invalid attribute kind");
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   291
    return _attributes[kind];
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   292
  }
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   293
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   294
  // Retrieve an attribute string value from the inflated array.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   295
  inline const char* get_attribute(u4 kind, const ImageStrings& strings) const {
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   296
    return strings.get((u4)get_attribute(kind));
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   297
  }
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   298
};
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   299
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   300
//
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   301
// NOTE: needs revision.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   302
// Each loader requires set of module meta data to identify which modules and
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   303
// packages are managed by that loader.  Currently, there is one image file per
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   304
// builtin loader, so only one  module meta data resource per file.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   305
//
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   306
// Each element in the module meta data is a native endian 4 byte integer.  Note
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   307
// that entries with zero offsets for string table entries should be ignored (
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   308
// padding for hash table lookup.)
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   309
//
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   310
// Format:
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   311
//    Count of package to module entries
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   312
//    Count of module to package entries
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   313
//    Perfect Hash redirect table[Count of package to module entries]
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   314
//    Package to module entries[Count of package to module entries]
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   315
//        Offset to package name in string table
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   316
//        Offset to module name in string table
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   317
//    Perfect Hash redirect table[Count of module to package entries]
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   318
//    Module to package entries[Count of module to package entries]
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   319
//        Offset to module name in string table
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   320
//        Count of packages in module
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   321
//        Offset to first package in packages table
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   322
//    Packages[]
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   323
//        Offset to package name in string table
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   324
//
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   325
// Manage the image module meta data.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   326
class ImageModuleData : public CHeapObj<mtClass> {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   327
  class Header VALUE_OBJ_CLASS_SPEC {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   328
  private:
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   329
    u4 _ptm_count;      // Count of package to module entries
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   330
    u4 _mtp_count;      // Count of module to package entries
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   331
  public:
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   332
    inline u4 ptm_count(Endian* endian) const { return endian->get(_ptm_count); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   333
    inline u4 mtp_count(Endian* endian) const { return endian->get(_mtp_count); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   334
  };
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   335
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   336
  // Hashtable entry
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   337
  class HashData VALUE_OBJ_CLASS_SPEC {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   338
  private:
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   339
    u4 _name_offset;    // Name offset in string table
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   340
  public:
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   341
    inline s4 name_offset(Endian* endian) const { return endian->get(_name_offset); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   342
  };
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   343
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   344
  // Package to module hashtable entry
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   345
  class PTMData : public HashData {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   346
  private:
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   347
    u4 _module_name_offset; // Module name offset in string table
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   348
  public:
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   349
    inline s4 module_name_offset(Endian* endian) const { return endian->get(_module_name_offset); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   350
  };
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   351
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   352
  // Module to package hashtable entry
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   353
  class MTPData : public HashData {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   354
  private:
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   355
    u4 _package_count;     // Number of packages in module
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   356
    u4 _package_offset;    // Offset in package list
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   357
  public:
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   358
    inline u4 package_count(Endian* endian)  const { return endian->get(_package_count); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   359
    inline u4 package_offset(Endian* endian) const { return endian->get(_package_offset); }
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   360
  };
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   361
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   362
  const ImageFileReader* _image_file; // Source image file
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   363
  Endian* _endian;                    // Endian handler
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   364
  ImageStrings _strings;              // Image file strings
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   365
  u1* _data;                          // Module data resource data
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   366
  u8 _data_size;                      // Size of resource data
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   367
  Header* _header;                    // Module data header
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   368
  s4* _ptm_redirect;                  // Package to module hashtable redirect
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   369
  PTMData* _ptm_data;                 // Package to module data
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   370
  s4* _mtp_redirect;                  // Module to packages hashtable redirect
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   371
  MTPData* _mtp_data;                 // Module to packages data
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   372
  s4* _mtp_packages;                  // Package data (name offsets)
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   373
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   374
  // Return a string from the string table.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   375
  inline const char* get_string(u4 offset) {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   376
    return _strings.get(offset);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   377
  }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   378
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   379
  inline u4 mtp_package(u4 index) {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   380
    return _endian->get(_mtp_packages[index]);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   381
  }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   382
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   383
public:
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   384
  ImageModuleData(const ImageFileReader* image_file, const char* module_data_name);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   385
  ~ImageModuleData();
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   386
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   387
  // Return the name of the module data resource.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   388
  static void module_data_name(char* buffer, const char* image_file_name);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   389
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   390
  // Return the module in which a package resides.  Returns NULL if not found.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   391
  const char* package_to_module(const char* package_name);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   392
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   393
  // Returns all the package names in a module.  Returns NULL if module not found.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   394
  GrowableArray<const char*>* module_to_packages(const char* module_name);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   395
};
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   396
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   397
// Image file header, starting at offset 0.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   398
class ImageHeader VALUE_OBJ_CLASS_SPEC {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   399
private:
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   400
  u4 _magic;           // Image file marker
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   401
  u4 _version;         // Image file major version number
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   402
  u4 _flags;           // Image file flags
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   403
  u4 _resource_count;  // Number of resources in file
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   404
  u4 _table_length;    // Number of slots in index tables
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   405
  u4 _locations_size;  // Number of bytes in attribute table
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   406
  u4 _strings_size;    // Number of bytes in string table
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   407
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   408
public:
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   409
  u4 magic() const { return _magic; }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   410
  u4 magic(Endian* endian) const { return endian->get(_magic); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   411
  void set_magic(Endian* endian, u4 magic) { return endian->set(_magic, magic); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   412
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   413
  u4 major_version(Endian* endian) const { return endian->get(_version) >> 16; }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   414
  u4 minor_version(Endian* endian) const { return endian->get(_version) & 0xFFFF; }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   415
  void set_version(Endian* endian, u4 major_version, u4 minor_version) {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   416
    return endian->set(_version, major_version << 16 | minor_version);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   417
  }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   418
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   419
  u4 flags(Endian* endian) const { return endian->get(_flags); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   420
  void set_flags(Endian* endian, u4 value) { return endian->set(_flags, value); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   421
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   422
  u4 resource_count(Endian* endian) const { return endian->get(_resource_count); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   423
  void set_resource_count(Endian* endian, u4 count) { return endian->set(_resource_count, count); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   424
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   425
  u4 table_length(Endian* endian) const { return endian->get(_table_length); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   426
  void set_table_length(Endian* endian, u4 count) { return endian->set(_table_length, count); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   427
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   428
  u4 locations_size(Endian* endian) const { return endian->get(_locations_size); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   429
  void set_locations_size(Endian* endian, u4 size) { return endian->set(_locations_size, size); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   430
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   431
  u4 strings_size(Endian* endian) const { return endian->get(_strings_size); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   432
  void set_strings_size(Endian* endian, u4 size) { return endian->set(_strings_size, size); }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   433
};
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   434
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   435
// Max path length limit independent of platform.  Windows max path is 1024,
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   436
// other platforms use 4096.  The JCK fails several tests when 1024 is used.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   437
#define IMAGE_MAX_PATH 4096
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   438
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   439
// Manage the image file.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   440
// ImageFileReader manages the content of an image file.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   441
// Initially, the header of the image file is read for validation.  If valid,
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   442
// values in the header are used calculate the size of the image index.  The
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   443
// index is then memory mapped to allow load on demand and sharing.  The
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   444
// -XX:+MemoryMapImage flag determines if the entire file is loaded (server use.)
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   445
// An image can be used by Hotspot and multiple reference points in the JDK, thus
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   446
// it is desirable to share a reader.  To accomodate sharing, a share table is
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   447
// defined (see ImageFileReaderTable in imageFile.cpp)  To track the number of
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   448
// uses, ImageFileReader keeps a use count (_use).  Use is incremented when
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   449
// 'opened' by reference point and decremented when 'closed'.  Use of zero
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   450
// leads the ImageFileReader to be actually closed and discarded.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   451
class ImageFileReader : public CHeapObj<mtClass> {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   452
private:
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   453
  // Manage a number of image files such that an image can be shared across
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   454
  // multiple uses (ex. loader.)
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   455
  static GrowableArray<ImageFileReader*>* _reader_table;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   456
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   457
  char* _name;         // Name of image
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   458
  s4 _use;             // Use count
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   459
  int _fd;             // File descriptor
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   460
  Endian* _endian;     // Endian handler
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   461
  u8 _file_size;       // File size in bytes
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   462
  ImageHeader _header; // Image header
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   463
  size_t _index_size;  // Total size of index
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   464
  u1* _index_data;     // Raw index data
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   465
  s4* _redirect_table; // Perfect hash redirect table
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   466
  u4* _offsets_table;  // Location offset table
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   467
  u1* _location_bytes; // Location attributes
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   468
  u1* _string_bytes;   // String table
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   469
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   470
  ImageFileReader(const char* name, bool big_endian);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   471
  ~ImageFileReader();
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   472
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   473
  // Compute number of bytes in image file index.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   474
  inline u8 index_size() {
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   475
    return sizeof(ImageHeader) +
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   476
      table_length() * sizeof(u4) * 2 + locations_size() + strings_size();
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   477
  }
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   478
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   479
public:
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   480
  enum {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   481
    // Image file marker.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   482
    IMAGE_MAGIC = 0xCAFEDADA,
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   483
    // Endian inverted Image file marker.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   484
    IMAGE_MAGIC_INVERT = 0xDADAFECA,
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   485
    // Image file major version number.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   486
    MAJOR_VERSION = 1,
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   487
    // Image file minor version number.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   488
    MINOR_VERSION = 0
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   489
  };
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   490
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   491
  // Open an image file, reuse structure if file already open.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   492
  static ImageFileReader* open(const char* name, bool big_endian = Endian::is_big_endian());
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   493
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   494
  // Close an image file if the file is not in use elsewhere.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   495
  static void close(ImageFileReader *reader);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   496
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   497
  // Return an id for the specifed ImageFileReader.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   498
  static u8 readerToID(ImageFileReader *reader);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   499
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   500
  // Validate the image id.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   501
  static bool idCheck(u8 id);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   502
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   503
  // Return an id for the specifed ImageFileReader.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   504
  static ImageFileReader* idToReader(u8 id);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   505
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   506
  // Open image file for read access.
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   507
  bool open();
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   508
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   509
  // Close image file.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   510
  void close();
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   511
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   512
  // Read directly from the file.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   513
  bool read_at(u1* data, u8 size, u8 offset) const;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   514
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   515
  inline Endian* endian() const { return _endian; }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   516
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   517
  // Retrieve name of image file.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   518
  inline const char* name() const {
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   519
    return _name;
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   520
  }
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   521
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   522
  // Retrieve size of image file.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   523
  inline u8 file_size() const {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   524
    return _file_size;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   525
  }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   526
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   527
  // Return first address of index data.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   528
  inline u1* get_index_address() const {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   529
    return _index_data;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   530
  }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   531
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   532
  // Return first address of resource data.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   533
  inline u1* get_data_address() const {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   534
    return _index_data + _index_size;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   535
  }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   536
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   537
  // Get the size of the index data.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   538
  size_t get_index_size() const {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   539
    return _index_size;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   540
  }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   541
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   542
  inline u4 table_length() const {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   543
    return _header.table_length(_endian);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   544
  }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   545
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   546
  inline u4 locations_size() const {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   547
    return _header.locations_size(_endian);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   548
  }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   549
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   550
  inline u4 strings_size()const  {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   551
    return _header.strings_size(_endian);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   552
  }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   553
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   554
  inline u4* offsets_table() const {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   555
    return _offsets_table;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   556
  }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   557
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   558
  // Increment use count.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   559
  inline void inc_use() {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   560
    _use++;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   561
  }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   562
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   563
  // Decrement use count.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   564
  inline bool dec_use() {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   565
    return --_use == 0;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   566
  }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   567
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   568
  // Return a string table accessor.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   569
  inline const ImageStrings get_strings() const {
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   570
    return ImageStrings(_string_bytes, _header.strings_size(_endian));
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   571
  }
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   572
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   573
  // Return location attribute stream at offset.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   574
  inline u1* get_location_offset_data(u4 offset) const {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   575
    guarantee((u4)offset < _header.locations_size(_endian),
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   576
              "offset exceeds location attributes size");
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   577
    return offset != 0 ? _location_bytes + offset : NULL;
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   578
  }
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   579
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   580
  // Return location attribute stream for location i.
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   581
  inline u1* get_location_data(u4 index) const {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   582
    guarantee((u4)index < _header.table_length(_endian),
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   583
              "index exceeds location count");
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   584
    u4 offset = _endian->get(_offsets_table[index]);
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   585
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   586
    return get_location_offset_data(offset);
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   587
  }
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   588
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   589
  // Find the location attributes associated with the path.  Returns true if
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   590
  // the location is found, false otherwise.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   591
  bool find_location(const char* path, ImageLocation& location) const;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   592
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   593
  // Assemble the location path.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   594
  void location_path(ImageLocation& location, char* path, size_t max) const;
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   595
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   596
  // Verify that a found location matches the supplied path.
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   597
  bool verify_location(ImageLocation& location, const char* path) const;
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   598
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   599
  // Return the resource for the supplied path.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents: 27562
diff changeset
   600
  void get_resource(ImageLocation& location, u1* uncompressed_data) const;
27562
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   601
};
47f369e3c69c 8049367: Modular Run-Time Images
chegar
parents:
diff changeset
   602
#endif // SHARE_VM_CLASSFILE_IMAGEFILE_HPP