hotspot/src/share/vm/classfile/sharedPathsMiscInfo.hpp
author alanb
Thu, 17 Mar 2016 19:04:01 +0000
changeset 36508 5f9eee6b383b
parent 36364 5971776598e5
child 40013 943cf01a6b82
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, harold.seigel@oracle.com, lois.foltan@oracle.com, calvin.cheung@oracle.com, christian.tornqvist@oracle.com, erik.joelsson@oracle.com, george.triantafillou@oracle.com, igor.ignatyev@oracle.com, ioi.lam@oracle.com, james.laskey@oracle.com, jean-francois.denise@oracle.com, jiangli.zhou@oracle.com, markus.gronlund@oracle.com, serguei.spitsyn@oracle.com, staffan.larsen@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
     1
/*
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 27880
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
     4
 *
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
     8
 *
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    13
 * accompanied this code).
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    14
 *
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    18
 *
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    21
 * questions.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    22
 *
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    23
 */
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    24
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    25
#ifndef SHARE_VM_CLASSFILE_SHAREDPATHSMISCINFO_HPP
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    26
#define SHARE_VM_CLASSFILE_SHAREDPATHSMISCINFO_HPP
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    27
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 27880
diff changeset
    28
#include "classfile/classLoader.hpp"
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    29
#include "runtime/os.hpp"
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    30
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    31
// During dumping time, when processing class paths, we build up the dump-time
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    32
// classpath. The JAR files that exist are stored in the list ClassLoader::_first_entry.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    33
// However, we need to store other "misc" information for run-time checking, such as
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    34
//
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    35
// + The values of Arguments::get_sysclasspath() used during dumping.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    36
//
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    37
// + The meta-index file(s) used during dumping (incl modification time and size)
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    38
//
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    39
// + The class path elements specified during dumping but did not exist --
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    40
//   these elements must also be specified at run time, and they also must not
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    41
//   exist at run time.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    42
//
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    43
// These misc items are stored in a linear buffer in SharedPathsMiscInfo.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    44
// The storage format is stream oriented to minimize its size.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    45
//
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    46
// When writing the information to the archive file, SharedPathsMiscInfo is stored in
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    47
// the archive file header. At run-time, this information is used only during initialization
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    48
// (accessed using read() instead of mmap()), and is deallocated afterwards to save space.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    49
//
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    50
// The SharedPathsMiscInfo class is used for both creating the the information (during
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    51
// dumping time) and validation (at run time). Different constructors are used in the
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    52
// two situations. See below.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    53
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    54
class SharedPathsMiscInfo : public CHeapObj<mtClass> {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    55
protected:
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    56
  char* _buf_start;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    57
  char* _cur_ptr;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    58
  char* _end_ptr;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    59
  int   _buf_size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    60
  bool  _allocated;   // was _buf_start allocated by me?
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    61
  void ensure_size(size_t needed_bytes);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    62
  void add_path(const char* path, int type);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    63
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    64
  void write(const void* ptr, size_t size);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    65
  bool read(void* ptr, size_t size);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    66
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    67
protected:
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    68
  static bool fail(const char* msg, const char* name = NULL);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    69
  virtual bool check(jint type, const char* path);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    70
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    71
public:
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    72
  enum {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    73
    INITIAL_BUF_SIZE = 128
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    74
  };
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    75
  // This constructor is used when creating the misc information (during dump)
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    76
  SharedPathsMiscInfo() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    77
    _buf_size = INITIAL_BUF_SIZE;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    78
    _cur_ptr = _buf_start = NEW_C_HEAP_ARRAY(char, _buf_size, mtClass);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    79
    _allocated = true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    80
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    81
  // This constructor is used when validating the misc info (during run time)
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    82
  SharedPathsMiscInfo(char *buff, int size) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    83
    _cur_ptr = _buf_start = buff;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    84
    _end_ptr = _buf_start + size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    85
    _buf_size = size;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    86
    _allocated = false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    87
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    88
  ~SharedPathsMiscInfo() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    89
    if (_allocated) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 26419
diff changeset
    90
      FREE_C_HEAP_ARRAY(char, _buf_start);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    91
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    92
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    93
  int get_used_bytes() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    94
    return _cur_ptr - _buf_start;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    95
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    96
  void* buffer() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    97
    return _buf_start;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    98
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
    99
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   100
  // writing --
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   101
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   102
  // The path must not exist at run-time
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   103
  void add_nonexist_path(const char* path) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   104
    add_path(path, NON_EXIST);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   105
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   106
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   107
  // The path must exist, and must contain exactly <num_entries> files/dirs
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   108
  void add_boot_classpath(const char* path) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   109
    add_path(path, BOOT);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   110
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   111
  int write_jint(jint num) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   112
    write(&num, sizeof(num));
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   113
    return 0;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   114
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   115
  void write_time(time_t t) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   116
    write(&t, sizeof(t));
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   117
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   118
  void write_long(long l) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   119
    write(&l, sizeof(l));
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   120
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   121
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   122
  bool dump_to_file(int fd) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   123
    int n = get_used_bytes();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   124
    return (os::write(fd, _buf_start, n) == (size_t)n);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   125
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   126
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   127
  // reading --
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   128
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   129
  enum {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   130
    BOOT      = 1,
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   131
    NON_EXIST = 2,
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   132
    REQUIRED  = 3
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   133
  };
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   134
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   135
  virtual const char* type_name(int type) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   136
    switch (type) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   137
    case BOOT:      return "BOOT";
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   138
    case NON_EXIST: return "NON_EXIST";
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   139
    case REQUIRED:  return "REQUIRED";
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   140
    default:        ShouldNotReachHere(); return "?";
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   141
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   142
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   143
36364
5971776598e5 8150103: Convert TraceClassPaths to Unified Logging
mockner
parents: 34287
diff changeset
   144
  virtual void print_path(int type, const char* path);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   145
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   146
  bool check();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   147
  bool read_jint(jint *ptr) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   148
    return read(ptr, sizeof(jint));
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   149
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   150
  bool read_long(long *ptr) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   151
    return read(ptr, sizeof(long));
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   152
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   153
  bool read_time(time_t *ptr) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   154
    return read(ptr, sizeof(time_t));
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   155
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   156
};
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   157
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents:
diff changeset
   158
#endif // SHARE_VM_CLASSFILE_SHAREDPATHSMISCINFO_HPP