Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/classfile/sharedPathsMiscInfo.hpp
32285 views
/*1* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_CLASSFILE_SHAREDPATHSMISCINFO_HPP25#define SHARE_VM_CLASSFILE_SHAREDPATHSMISCINFO_HPP2627#include "runtime/os.hpp"2829// During dumping time, when processing class paths, we build up the dump-time30// classpath. The JAR files that exist are stored in the list ClassLoader::_first_entry.31// However, we need to store other "misc" information for run-time checking, such as32//33// + The values of Arguments::get_sysclasspath() used during dumping.34//35// + The meta-index file(s) used during dumping (incl modification time and size)36//37// + The class path elements specified during dumping but did not exist --38// these elements must also be specified at run time, and they also must not39// exist at run time.40//41// These misc items are stored in a linear buffer in SharedPathsMiscInfo.42// The storage format is stream oriented to minimize its size.43//44// When writing the information to the archive file, SharedPathsMiscInfo is stored in45// the archive file header. At run-time, this information is used only during initialization46// (accessed using read() instead of mmap()), and is deallocated afterwards to save space.47//48// The SharedPathsMiscInfo class is used for both creating the the information (during49// dumping time) and validation (at run time). Different constructors are used in the50// two situations. See below.5152class SharedPathsMiscInfo : public CHeapObj<mtClass> {53protected:54char* _buf_start;55char* _cur_ptr;56char* _end_ptr;57int _buf_size;58bool _allocated; // was _buf_start allocated by me?59void ensure_size(size_t needed_bytes);60void add_path(const char* path, int type);6162void write(const void* ptr, size_t size);63bool read(void* ptr, size_t size);6465static void trace_class_path(const char* msg, const char* name = NULL) {66ClassLoader::trace_class_path(tty, msg, name);67}68protected:69static bool fail(const char* msg, const char* name = NULL);70virtual bool check(jint type, const char* path);7172public:73enum {74INITIAL_BUF_SIZE = 12875};76// This constructor is used when creating the misc information (during dump)77SharedPathsMiscInfo() {78_buf_size = INITIAL_BUF_SIZE;79_cur_ptr = _buf_start = NEW_C_HEAP_ARRAY(char, _buf_size, mtClass);80_allocated = true;81}82// This constructor is used when validating the misc info (during run time)83SharedPathsMiscInfo(char *buff, int size) {84_cur_ptr = _buf_start = buff;85_end_ptr = _buf_start + size;86_buf_size = size;87_allocated = false;88}89~SharedPathsMiscInfo() {90if (_allocated) {91FREE_C_HEAP_ARRAY(char, _buf_start, mtClass);92}93}94int get_used_bytes() {95return _cur_ptr - _buf_start;96}97void* buffer() {98return _buf_start;99}100101// writing --102103// The path must not exist at run-time104void add_nonexist_path(const char* path) {105add_path(path, NON_EXIST);106}107108// The path must exist and have required size and modification time109void add_required_file(const char* path) {110add_path(path, REQUIRED);111112struct stat st;113if (os::stat(path, &st) != 0) {114assert(0, "sanity");115ClassLoader::exit_with_path_failure("failed to os::stat(%s)", path); // should not happen116}117write_time(st.st_mtime);118write_long(st.st_size);119}120121// The path must exist, and must contain exactly <num_entries> files/dirs122void add_boot_classpath(const char* path) {123add_path(path, BOOT);124}125int write_jint(jint num) {126write(&num, sizeof(num));127return 0;128}129void write_time(time_t t) {130write(&t, sizeof(t));131}132void write_long(long l) {133write(&l, sizeof(l));134}135136bool dump_to_file(int fd) {137int n = get_used_bytes();138return (os::write(fd, _buf_start, n) == (size_t)n);139}140141// reading --142143enum {144BOOT = 1,145NON_EXIST = 2,146REQUIRED = 3147};148149virtual const char* type_name(int type) {150switch (type) {151case BOOT: return "BOOT";152case NON_EXIST: return "NON_EXIST";153case REQUIRED: return "REQUIRED";154default: ShouldNotReachHere(); return "?";155}156}157158virtual void print_path(outputStream* out, int type, const char* path) {159switch (type) {160case BOOT:161out->print("Expecting -Dsun.boot.class.path=%s", path);162break;163case NON_EXIST:164out->print("Expecting that %s does not exist", path);165break;166case REQUIRED:167out->print("Expecting that file %s must exist and is not altered", path);168break;169default:170ShouldNotReachHere();171}172}173174bool check();175bool read_jint(jint *ptr) {176return read(ptr, sizeof(jint));177}178bool read_long(long *ptr) {179return read(ptr, sizeof(long));180}181bool read_time(time_t *ptr) {182return read(ptr, sizeof(time_t));183}184};185186#endif // SHARE_VM_CLASSFILE_SHAREDPATHSMISCINFO_HPP187188189