2014-08-12 17:29:00 -07:00
|
|
|
/*
|
2018-03-15 21:29:36 +01:00
|
|
|
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
|
2014-08-12 17:29:00 -07:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.hpp"
|
|
|
|
#include "classfile/classLoader.hpp"
|
|
|
|
#include "classfile/sharedPathsMiscInfo.hpp"
|
2016-02-25 13:09:17 -05:00
|
|
|
#include "logging/log.hpp"
|
2017-07-21 09:50:12 +02:00
|
|
|
#include "logging/logStream.hpp"
|
2014-08-12 17:29:00 -07:00
|
|
|
#include "memory/allocation.inline.hpp"
|
2018-05-21 15:15:58 -04:00
|
|
|
#include "memory/filemap.hpp"
|
2014-08-12 17:29:00 -07:00
|
|
|
#include "memory/metaspaceShared.hpp"
|
2016-04-04 12:57:48 -04:00
|
|
|
#include "memory/resourceArea.hpp"
|
2014-08-12 17:29:00 -07:00
|
|
|
#include "runtime/arguments.hpp"
|
2018-03-15 21:29:36 +01:00
|
|
|
#include "runtime/os.inline.hpp"
|
2016-02-25 13:09:17 -05:00
|
|
|
#include "utilities/ostream.hpp"
|
2014-08-12 17:29:00 -07:00
|
|
|
|
2017-11-28 21:43:45 +01:00
|
|
|
SharedPathsMiscInfo::SharedPathsMiscInfo() {
|
2018-04-26 13:40:58 -07:00
|
|
|
_app_offset = 0;
|
2017-11-28 21:43:45 +01:00
|
|
|
_buf_size = INITIAL_BUF_SIZE;
|
|
|
|
_cur_ptr = _buf_start = NEW_C_HEAP_ARRAY(char, _buf_size, mtClass);
|
|
|
|
_allocated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedPathsMiscInfo::~SharedPathsMiscInfo() {
|
|
|
|
if (_allocated) {
|
|
|
|
FREE_C_HEAP_ARRAY(char, _buf_start);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-12 17:29:00 -07:00
|
|
|
void SharedPathsMiscInfo::add_path(const char* path, int type) {
|
2016-04-29 22:40:51 -04:00
|
|
|
log_info(class, path)("type=%s ", type_name(type));
|
2016-02-25 13:09:17 -05:00
|
|
|
ClassLoader::trace_class_path("add misc shared path ", path);
|
2014-08-12 17:29:00 -07:00
|
|
|
write(path, strlen(path) + 1);
|
|
|
|
write_jint(jint(type));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SharedPathsMiscInfo::ensure_size(size_t needed_bytes) {
|
|
|
|
assert(_allocated, "cannot modify buffer during validation.");
|
|
|
|
int used = get_used_bytes();
|
|
|
|
int target = used + int(needed_bytes);
|
|
|
|
if (target > _buf_size) {
|
|
|
|
_buf_size = _buf_size * 2 + (int)needed_bytes;
|
|
|
|
_buf_start = REALLOC_C_HEAP_ARRAY(char, _buf_start, _buf_size, mtClass);
|
|
|
|
_cur_ptr = _buf_start + used;
|
|
|
|
_end_ptr = _buf_start + _buf_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SharedPathsMiscInfo::write(const void* ptr, size_t size) {
|
|
|
|
ensure_size(size);
|
|
|
|
memcpy(_cur_ptr, ptr, size);
|
|
|
|
_cur_ptr += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SharedPathsMiscInfo::read(void* ptr, size_t size) {
|
|
|
|
if (_cur_ptr + size <= _end_ptr) {
|
|
|
|
memcpy(ptr, _cur_ptr, size);
|
|
|
|
_cur_ptr += size;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SharedPathsMiscInfo::fail(const char* msg, const char* name) {
|
2016-02-25 13:09:17 -05:00
|
|
|
ClassLoader::trace_class_path(msg, name);
|
2014-08-12 17:29:00 -07:00
|
|
|
MetaspaceShared::set_archive_loading_failed();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-21 09:50:12 +02:00
|
|
|
void SharedPathsMiscInfo::print_path(outputStream* out, int type, const char* path) {
|
2016-02-25 13:09:17 -05:00
|
|
|
switch (type) {
|
2018-04-26 13:40:58 -07:00
|
|
|
case BOOT_PATH:
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
out->print("Expecting BOOT path=%s", path);
|
2016-02-25 13:09:17 -05:00
|
|
|
break;
|
|
|
|
case NON_EXIST:
|
|
|
|
out->print("Expecting that %s does not exist", path);
|
|
|
|
break;
|
2018-04-26 13:40:58 -07:00
|
|
|
case APP_PATH:
|
|
|
|
ClassLoader::trace_class_path("Expecting -Djava.class.path=", path);
|
|
|
|
break;
|
2016-02-25 13:09:17 -05:00
|
|
|
default:
|
|
|
|
ShouldNotReachHere();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-12 17:29:00 -07:00
|
|
|
bool SharedPathsMiscInfo::check() {
|
|
|
|
// The whole buffer must be 0 terminated so that we can use strlen and strcmp
|
|
|
|
// without fear.
|
|
|
|
_end_ptr -= sizeof(jint);
|
|
|
|
if (_cur_ptr >= _end_ptr) {
|
|
|
|
return fail("Truncated archive file header");
|
|
|
|
}
|
|
|
|
if (*_end_ptr != 0) {
|
|
|
|
return fail("Corrupted archive file header");
|
|
|
|
}
|
|
|
|
|
|
|
|
while (_cur_ptr < _end_ptr) {
|
|
|
|
jint type;
|
|
|
|
const char* path = _cur_ptr;
|
|
|
|
_cur_ptr += strlen(path) + 1;
|
|
|
|
if (!read_jint(&type)) {
|
|
|
|
return fail("Corrupted archive file header");
|
|
|
|
}
|
2017-07-21 09:50:12 +02:00
|
|
|
LogTarget(Info, class, path) lt;
|
|
|
|
if (lt.is_enabled()) {
|
|
|
|
lt.print("type=%s ", type_name(type));
|
|
|
|
LogStream ls(lt);
|
|
|
|
print_path(&ls, type, path);
|
|
|
|
ls.cr();
|
|
|
|
}
|
2014-08-12 17:29:00 -07:00
|
|
|
if (!check(type, path)) {
|
|
|
|
if (!PrintSharedArchiveAndExit) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
2016-02-25 13:09:17 -05:00
|
|
|
ClassLoader::trace_class_path("ok");
|
2014-08-12 17:29:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-21 15:15:58 -04:00
|
|
|
char* skip_first_path_entry(const char* path) {
|
|
|
|
size_t path_sep_len = strlen(os::path_separator());
|
|
|
|
char* p = strstr((char*)path, os::path_separator());
|
|
|
|
if (p != NULL) {
|
|
|
|
debug_only( {
|
|
|
|
size_t image_name_len = strlen(MODULES_IMAGE_NAME);
|
|
|
|
assert(strncmp(p - image_name_len, MODULES_IMAGE_NAME, image_name_len) == 0,
|
|
|
|
"first entry must be the modules image");
|
|
|
|
} );
|
|
|
|
p += path_sep_len;
|
|
|
|
} else {
|
|
|
|
debug_only( {
|
|
|
|
assert(ClassLoader::string_ends_with(path, MODULES_IMAGE_NAME),
|
|
|
|
"first entry must be the modules image");
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2014-08-12 17:29:00 -07:00
|
|
|
bool SharedPathsMiscInfo::check(jint type, const char* path) {
|
2018-05-21 15:15:58 -04:00
|
|
|
assert(UseSharedSpaces, "runtime only");
|
2014-08-12 17:29:00 -07:00
|
|
|
switch (type) {
|
2018-04-26 13:40:58 -07:00
|
|
|
case BOOT_PATH:
|
2018-05-21 15:15:58 -04:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// - Archive contains boot classes only - relaxed boot path check:
|
|
|
|
// Extra path elements appended to the boot path at runtime are allowed.
|
|
|
|
//
|
|
|
|
// - Archive contains application or platform classes - strict boot path check:
|
|
|
|
// Validate the entire runtime boot path, which must be compactible
|
|
|
|
// with the dump time boot path. Appending boot path at runtime is not
|
|
|
|
// allowed.
|
|
|
|
//
|
|
|
|
|
|
|
|
// The first entry in boot path is the modules_image (guaranteed by
|
|
|
|
// ClassLoader::setup_boot_search_path()). Skip the first entry. The
|
|
|
|
// path of the runtime modules_image may be different from the dump
|
|
|
|
// time path (e.g. the JDK image is copied to a different location
|
|
|
|
// after generating the shared archive), which is acceptable. For most
|
|
|
|
// common cases, the dump time boot path might contain modules_image only.
|
|
|
|
char* runtime_boot_path = Arguments::get_sysclasspath();
|
|
|
|
char* rp = skip_first_path_entry(runtime_boot_path);
|
|
|
|
char* dp = skip_first_path_entry(path);
|
|
|
|
|
|
|
|
bool relaxed_check = !FileMapInfo::current_info()->header()->has_platform_or_app_classes();
|
|
|
|
if (dp == NULL && rp == NULL) {
|
|
|
|
break; // ok, both runtime and dump time boot paths have modules_images only
|
|
|
|
} else if (dp == NULL && rp != NULL && relaxed_check) {
|
|
|
|
break; // ok, relaxed check, runtime has extra boot append path entries
|
|
|
|
} else if (dp != NULL && rp != NULL) {
|
|
|
|
size_t num;
|
|
|
|
size_t dp_len = strlen(dp);
|
|
|
|
size_t rp_len = strlen(rp);
|
|
|
|
if (rp_len >= dp_len) {
|
|
|
|
if (relaxed_check) {
|
|
|
|
// only check the leading entries in the runtime boot path, up to
|
|
|
|
// the length of the dump time boot path
|
|
|
|
num = dp_len;
|
|
|
|
} else {
|
|
|
|
// check the full runtime boot path, must match with dump time
|
|
|
|
num = rp_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (os::file_name_strncmp(dp, rp, num) == 0) {
|
|
|
|
// make sure it is the end of an entry in the runtime boot path
|
|
|
|
if (rp[dp_len] == '\0' || rp[dp_len] == os::path_separator()[0]) {
|
|
|
|
break; // ok, runtime and dump time paths match
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The paths are different
|
|
|
|
return fail("[BOOT classpath mismatch, actual =", runtime_boot_path);
|
2014-08-12 17:29:00 -07:00
|
|
|
}
|
|
|
|
break;
|
2017-04-05 18:15:09 -04:00
|
|
|
case NON_EXIST:
|
2014-08-12 17:29:00 -07:00
|
|
|
{
|
|
|
|
struct stat st;
|
2017-04-05 18:15:09 -04:00
|
|
|
if (os::stat(path, &st) == 0) {
|
2014-08-12 17:29:00 -07:00
|
|
|
// The file actually exists
|
2017-04-05 18:15:09 -04:00
|
|
|
// But we want it to not exist -> fail
|
|
|
|
return fail("File must not exist");
|
2014-08-12 17:29:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2018-04-26 13:40:58 -07:00
|
|
|
case APP_PATH:
|
|
|
|
{
|
|
|
|
size_t len = strlen(path);
|
|
|
|
const char *appcp = Arguments::get_appclasspath();
|
|
|
|
assert(appcp != NULL, "NULL app classpath");
|
|
|
|
size_t appcp_len = strlen(appcp);
|
|
|
|
if (appcp_len < len) {
|
|
|
|
return fail("Run time APP classpath is shorter than the one at dump time: ", appcp);
|
|
|
|
}
|
2018-05-21 15:15:58 -04:00
|
|
|
// Prefix is OK: E.g., dump with -cp foo.jar, but run with -cp foo.jar:bar.jar.
|
|
|
|
if (os::file_name_strncmp(path, appcp, len) != 0) {
|
2018-04-26 13:40:58 -07:00
|
|
|
return fail("[APP classpath mismatch, actual: -Djava.class.path=", appcp);
|
|
|
|
}
|
|
|
|
if (appcp[len] != '\0' && appcp[len] != os::path_separator()[0]) {
|
|
|
|
return fail("Dump time APP classpath is not a proper prefix of run time APP classpath: ", appcp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-08-12 17:29:00 -07:00
|
|
|
default:
|
|
|
|
return fail("Corrupted archive file header");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|