Wed, 19 Nov 2014 18:14:01 +0100
8065361: Fixup headers and definitions for INCLUDE_TRACE
Reviewed-by: sla, stefank
iklam@7089 | 1 | /* |
iklam@7089 | 2 | * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
iklam@7089 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
iklam@7089 | 4 | * |
iklam@7089 | 5 | * This code is free software; you can redistribute it and/or modify it |
iklam@7089 | 6 | * under the terms of the GNU General Public License version 2 only, as |
iklam@7089 | 7 | * published by the Free Software Foundation. |
iklam@7089 | 8 | * |
iklam@7089 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
iklam@7089 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
iklam@7089 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
iklam@7089 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
iklam@7089 | 13 | * accompanied this code). |
iklam@7089 | 14 | * |
iklam@7089 | 15 | * You should have received a copy of the GNU General Public License version |
iklam@7089 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
iklam@7089 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
iklam@7089 | 18 | * |
iklam@7089 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
iklam@7089 | 20 | * or visit www.oracle.com if you need additional information or have any |
iklam@7089 | 21 | * questions. |
iklam@7089 | 22 | * |
iklam@7089 | 23 | */ |
iklam@7089 | 24 | |
iklam@7089 | 25 | #ifndef SHARE_VM_CLASSFILE_SHAREDPATHSMISCINFO_HPP |
iklam@7089 | 26 | #define SHARE_VM_CLASSFILE_SHAREDPATHSMISCINFO_HPP |
iklam@7089 | 27 | |
iklam@7089 | 28 | #include "runtime/os.hpp" |
iklam@7089 | 29 | |
iklam@7089 | 30 | // During dumping time, when processing class paths, we build up the dump-time |
iklam@7089 | 31 | // classpath. The JAR files that exist are stored in the list ClassLoader::_first_entry. |
iklam@7089 | 32 | // However, we need to store other "misc" information for run-time checking, such as |
iklam@7089 | 33 | // |
iklam@7089 | 34 | // + The values of Arguments::get_sysclasspath() used during dumping. |
iklam@7089 | 35 | // |
iklam@7089 | 36 | // + The meta-index file(s) used during dumping (incl modification time and size) |
iklam@7089 | 37 | // |
iklam@7089 | 38 | // + The class path elements specified during dumping but did not exist -- |
iklam@7089 | 39 | // these elements must also be specified at run time, and they also must not |
iklam@7089 | 40 | // exist at run time. |
iklam@7089 | 41 | // |
iklam@7089 | 42 | // These misc items are stored in a linear buffer in SharedPathsMiscInfo. |
iklam@7089 | 43 | // The storage format is stream oriented to minimize its size. |
iklam@7089 | 44 | // |
iklam@7089 | 45 | // When writing the information to the archive file, SharedPathsMiscInfo is stored in |
iklam@7089 | 46 | // the archive file header. At run-time, this information is used only during initialization |
iklam@7089 | 47 | // (accessed using read() instead of mmap()), and is deallocated afterwards to save space. |
iklam@7089 | 48 | // |
iklam@7089 | 49 | // The SharedPathsMiscInfo class is used for both creating the the information (during |
iklam@7089 | 50 | // dumping time) and validation (at run time). Different constructors are used in the |
iklam@7089 | 51 | // two situations. See below. |
iklam@7089 | 52 | |
iklam@7089 | 53 | class SharedPathsMiscInfo : public CHeapObj<mtClass> { |
iklam@7089 | 54 | protected: |
iklam@7089 | 55 | char* _buf_start; |
iklam@7089 | 56 | char* _cur_ptr; |
iklam@7089 | 57 | char* _end_ptr; |
iklam@7089 | 58 | int _buf_size; |
iklam@7089 | 59 | bool _allocated; // was _buf_start allocated by me? |
iklam@7089 | 60 | void ensure_size(size_t needed_bytes); |
iklam@7089 | 61 | void add_path(const char* path, int type); |
iklam@7089 | 62 | |
iklam@7089 | 63 | void write(const void* ptr, size_t size); |
iklam@7089 | 64 | bool read(void* ptr, size_t size); |
iklam@7089 | 65 | |
iklam@7089 | 66 | static void trace_class_path(const char* msg, const char* name = NULL) { |
iklam@7089 | 67 | ClassLoader::trace_class_path(msg, name); |
iklam@7089 | 68 | } |
iklam@7089 | 69 | protected: |
iklam@7089 | 70 | static bool fail(const char* msg, const char* name = NULL); |
iklam@7089 | 71 | virtual bool check(jint type, const char* path); |
iklam@7089 | 72 | |
iklam@7089 | 73 | public: |
iklam@7089 | 74 | enum { |
iklam@7089 | 75 | INITIAL_BUF_SIZE = 128 |
iklam@7089 | 76 | }; |
iklam@7089 | 77 | // This constructor is used when creating the misc information (during dump) |
iklam@7089 | 78 | SharedPathsMiscInfo() { |
iklam@7089 | 79 | _buf_size = INITIAL_BUF_SIZE; |
iklam@7089 | 80 | _cur_ptr = _buf_start = NEW_C_HEAP_ARRAY(char, _buf_size, mtClass); |
iklam@7089 | 81 | _allocated = true; |
iklam@7089 | 82 | } |
iklam@7089 | 83 | // This constructor is used when validating the misc info (during run time) |
iklam@7089 | 84 | SharedPathsMiscInfo(char *buff, int size) { |
iklam@7089 | 85 | _cur_ptr = _buf_start = buff; |
iklam@7089 | 86 | _end_ptr = _buf_start + size; |
iklam@7089 | 87 | _buf_size = size; |
iklam@7089 | 88 | _allocated = false; |
iklam@7089 | 89 | } |
iklam@7089 | 90 | ~SharedPathsMiscInfo() { |
iklam@7089 | 91 | if (_allocated) { |
iklam@7089 | 92 | FREE_C_HEAP_ARRAY(char, _buf_start, mtClass); |
iklam@7089 | 93 | } |
iklam@7089 | 94 | } |
iklam@7089 | 95 | int get_used_bytes() { |
iklam@7089 | 96 | return _cur_ptr - _buf_start; |
iklam@7089 | 97 | } |
iklam@7089 | 98 | void* buffer() { |
iklam@7089 | 99 | return _buf_start; |
iklam@7089 | 100 | } |
iklam@7089 | 101 | |
iklam@7089 | 102 | // writing -- |
iklam@7089 | 103 | |
iklam@7089 | 104 | // The path must not exist at run-time |
iklam@7089 | 105 | void add_nonexist_path(const char* path) { |
iklam@7089 | 106 | add_path(path, NON_EXIST); |
iklam@7089 | 107 | } |
iklam@7089 | 108 | |
iklam@7089 | 109 | // The path must exist and have required size and modification time |
iklam@7089 | 110 | void add_required_file(const char* path) { |
iklam@7089 | 111 | add_path(path, REQUIRED); |
iklam@7089 | 112 | |
iklam@7089 | 113 | struct stat st; |
iklam@7089 | 114 | if (os::stat(path, &st) != 0) { |
iklam@7089 | 115 | assert(0, "sanity"); |
iklam@7089 | 116 | ClassLoader::exit_with_path_failure("failed to os::stat(%s)", path); // should not happen |
iklam@7089 | 117 | } |
iklam@7089 | 118 | write_time(st.st_mtime); |
iklam@7089 | 119 | write_long(st.st_size); |
iklam@7089 | 120 | } |
iklam@7089 | 121 | |
iklam@7089 | 122 | // The path must exist, and must contain exactly <num_entries> files/dirs |
iklam@7089 | 123 | void add_boot_classpath(const char* path) { |
iklam@7089 | 124 | add_path(path, BOOT); |
iklam@7089 | 125 | } |
iklam@7089 | 126 | int write_jint(jint num) { |
iklam@7089 | 127 | write(&num, sizeof(num)); |
iklam@7089 | 128 | return 0; |
iklam@7089 | 129 | } |
iklam@7089 | 130 | void write_time(time_t t) { |
iklam@7089 | 131 | write(&t, sizeof(t)); |
iklam@7089 | 132 | } |
iklam@7089 | 133 | void write_long(long l) { |
iklam@7089 | 134 | write(&l, sizeof(l)); |
iklam@7089 | 135 | } |
iklam@7089 | 136 | |
iklam@7089 | 137 | bool dump_to_file(int fd) { |
iklam@7089 | 138 | int n = get_used_bytes(); |
iklam@7089 | 139 | return (os::write(fd, _buf_start, n) == (size_t)n); |
iklam@7089 | 140 | } |
iklam@7089 | 141 | |
iklam@7089 | 142 | // reading -- |
iklam@7089 | 143 | |
iklam@7089 | 144 | enum { |
iklam@7089 | 145 | BOOT = 1, |
iklam@7089 | 146 | NON_EXIST = 2, |
iklam@7089 | 147 | REQUIRED = 3 |
iklam@7089 | 148 | }; |
iklam@7089 | 149 | |
iklam@7089 | 150 | virtual const char* type_name(int type) { |
iklam@7089 | 151 | switch (type) { |
iklam@7089 | 152 | case BOOT: return "BOOT"; |
iklam@7089 | 153 | case NON_EXIST: return "NON_EXIST"; |
iklam@7089 | 154 | case REQUIRED: return "REQUIRED"; |
iklam@7089 | 155 | default: ShouldNotReachHere(); return "?"; |
iklam@7089 | 156 | } |
iklam@7089 | 157 | } |
iklam@7089 | 158 | |
iklam@7089 | 159 | virtual void print_path(outputStream* out, int type, const char* path) { |
iklam@7089 | 160 | switch (type) { |
iklam@7089 | 161 | case BOOT: |
iklam@7089 | 162 | out->print("Expecting -Dsun.boot.class.path=%s", path); |
iklam@7089 | 163 | break; |
iklam@7089 | 164 | case NON_EXIST: |
iklam@7089 | 165 | out->print("Expecting that %s does not exist", path); |
iklam@7089 | 166 | break; |
iklam@7089 | 167 | case REQUIRED: |
iklam@7090 | 168 | out->print("Expecting that file %s must exist and is not altered", path); |
iklam@7089 | 169 | break; |
iklam@7089 | 170 | default: |
iklam@7089 | 171 | ShouldNotReachHere(); |
iklam@7089 | 172 | } |
iklam@7089 | 173 | } |
iklam@7089 | 174 | |
iklam@7089 | 175 | bool check(); |
iklam@7089 | 176 | bool read_jint(jint *ptr) { |
iklam@7089 | 177 | return read(ptr, sizeof(jint)); |
iklam@7089 | 178 | } |
iklam@7089 | 179 | bool read_long(long *ptr) { |
iklam@7089 | 180 | return read(ptr, sizeof(long)); |
iklam@7089 | 181 | } |
iklam@7089 | 182 | bool read_time(time_t *ptr) { |
iklam@7089 | 183 | return read(ptr, sizeof(time_t)); |
iklam@7089 | 184 | } |
iklam@7089 | 185 | }; |
iklam@7089 | 186 | |
iklam@7089 | 187 | #endif // SHARE_VM_CLASSFILE_SHAREDPATHSMISCINFO_HPP |