Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8276790: Rename GenericCDSFileMapHeader::_base_archive_path_offset #6288

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -35,7 +35,7 @@ CDSConst CDSConstants::offsets[] = {
{ "GenericCDSFileMapHeader::_crc", offset_of(GenericCDSFileMapHeader, _crc) },
{ "GenericCDSFileMapHeader::_version", offset_of(GenericCDSFileMapHeader, _version) },
{ "GenericCDSFileMapHeader::_header_size", offset_of(GenericCDSFileMapHeader, _header_size) },
{ "GenericCDSFileMapHeader::_base_archive_path_offset", offset_of(GenericCDSFileMapHeader, _base_archive_path_offset) },
{ "GenericCDSFileMapHeader::_base_archive_name_offset", offset_of(GenericCDSFileMapHeader, _base_archive_name_offset) },
{ "GenericCDSFileMapHeader::_base_archive_name_size", offset_of(GenericCDSFileMapHeader, _base_archive_name_size) },
{ "CDSFileMapHeaderBase::_space[0]", offset_of(CDSFileMapHeaderBase, _space) },
{ "FileMapHeader::_jvm_ident", offset_of(FileMapHeader, _jvm_ident) },
@@ -196,7 +196,7 @@ void FileMapInfo::populate_header(size_t core_region_alignment) {
size_t c_header_size;
size_t header_size;
size_t base_archive_name_size = 0;
size_t base_archive_path_offset = 0;
size_t base_archive_name_offset = 0;
if (is_static()) {
c_header_size = sizeof(FileMapHeader);
header_size = c_header_size;
@@ -207,7 +207,7 @@ void FileMapInfo::populate_header(size_t core_region_alignment) {
if (!FLAG_IS_DEFAULT(SharedArchiveFile)) {
base_archive_name_size = strlen(Arguments::GetSharedArchivePath()) + 1;
header_size += base_archive_name_size;
base_archive_path_offset = c_header_size;
base_archive_name_offset = c_header_size;
}
}
_header = (FileMapHeader*)os::malloc(header_size, mtInternal);
@@ -216,17 +216,17 @@ void FileMapInfo::populate_header(size_t core_region_alignment) {
core_region_alignment,
header_size,
base_archive_name_size,
base_archive_path_offset);
base_archive_name_offset);
}

void FileMapHeader::populate(FileMapInfo *info, size_t core_region_alignment,
size_t header_size, size_t base_archive_name_size,
size_t base_archive_path_offset) {
size_t base_archive_name_offset) {
// 1. We require _generic_header._magic to be at the beginning of the file
// 2. FileMapHeader also assumes that _generic_header is at the beginning of the file
assert(offset_of(FileMapHeader, _generic_header) == 0, "must be");
set_header_size((unsigned int)header_size);
set_base_archive_path_offset((unsigned int)base_archive_path_offset);
set_base_archive_name_offset((unsigned int)base_archive_name_offset);
set_base_archive_name_size((unsigned int)base_archive_name_size);
set_magic(DynamicDumpSharedSpaces ? CDS_DYNAMIC_ARCHIVE_MAGIC : CDS_ARCHIVE_MAGIC);
set_version(CURRENT_CDS_ARCHIVE_VERSION);
@@ -280,9 +280,9 @@ void FileMapHeader::populate(FileMapInfo *info, size_t core_region_alignment,

void FileMapHeader::copy_base_archive_name(const char* archive) {
assert(base_archive_name_size() != 0, "_base_archive_name_size not set");
assert(base_archive_path_offset() != 0, "_base_archive_path_offset not set");
assert(base_archive_name_offset() != 0, "_base_archive_name_offset not set");
assert(header_size() > sizeof(*this), "_base_archive_name_size not included in header size?");
memcpy((char*)this + base_archive_path_offset(), archive, base_archive_name_size());
memcpy((char*)this + base_archive_name_offset(), archive, base_archive_name_size());
}

void FileMapHeader::print(outputStream* st) {
@@ -292,7 +292,7 @@ void FileMapHeader::print(outputStream* st) {
st->print_cr("- crc: 0x%08x", crc());
st->print_cr("- version: %d", version());
st->print_cr("- header_size: " UINT32_FORMAT, header_size());
st->print_cr("- base_archive_path_offset: " UINT32_FORMAT, base_archive_path_offset());
st->print_cr("- base_archive_name_offset: " UINT32_FORMAT, base_archive_name_offset());
st->print_cr("- base_archive_name_size: " UINT32_FORMAT, base_archive_name_size());

for (int i = 0; i < NUM_CDS_REGIONS; i++) {
@@ -1088,7 +1088,7 @@ class FileHeaderHelper {
size_t name_size = _header._base_archive_name_size;
assert(name_size != 0, "For non-default base archive, name size should be non-zero!");
char* base_name = NEW_C_HEAP_ARRAY(char, name_size, mtInternal);
lseek(_fd, _header._base_archive_path_offset, SEEK_SET); // position to correct offset.
lseek(_fd, _header._base_archive_name_offset, SEEK_SET); // position to correct offset.
size_t n = os::read(_fd, base_name, (unsigned int)name_size);
if (n != name_size) {
log_info(cds)("Unable to read base archive name from archive");
@@ -1124,9 +1124,9 @@ bool FileMapInfo::check_archive(const char* archive_name, bool is_static) {
vm_exit_during_initialization("Not a base shared archive", archive_name);
return false;
}
if (header->_base_archive_path_offset != 0) {
log_info(cds)("_base_archive_path_offset should be 0");
log_info(cds)("_base_archive_path_offset = " UINT32_FORMAT, header->_base_archive_path_offset);
if (header->_base_archive_name_offset != 0) {
log_info(cds)("_base_archive_name_offset should be 0");
log_info(cds)("_base_archive_name_offset = " UINT32_FORMAT, header->_base_archive_name_offset);
return false;
}
} else {
@@ -1135,12 +1135,12 @@ bool FileMapInfo::check_archive(const char* archive_name, bool is_static) {
return false;
}
unsigned int name_size = header->_base_archive_name_size;
unsigned int path_offset = header->_base_archive_path_offset;
unsigned int name_offset = header->_base_archive_name_offset;
unsigned int header_size = header->_header_size;
if (path_offset + name_size != header_size) {
log_info(cds)("_header_size should be equal to _base_archive_path_offset plus _base_archive_name_size");
if (name_offset + name_size != header_size) {
log_info(cds)("_header_size should be equal to _base_archive_name_offset plus _base_archive_name_size");
log_info(cds)(" _base_archive_name_size = " UINT32_FORMAT, name_size);
log_info(cds)(" _base_archive_path_offset = " UINT32_FORMAT, path_offset);
log_info(cds)(" _base_archive_name_offset = " UINT32_FORMAT, name_offset);
log_info(cds)(" _header_size = " UINT32_FORMAT, header_size);
return false;
}
@@ -1165,13 +1165,13 @@ bool FileMapInfo::get_base_archive_name_from_header(const char* archive_name,
return false;
}

if ((header->_base_archive_name_size == 0 && header->_base_archive_path_offset != 0) ||
(header->_base_archive_name_size != 0 && header->_base_archive_path_offset == 0)) {
if ((header->_base_archive_name_size == 0 && header->_base_archive_name_offset != 0) ||
(header->_base_archive_name_size != 0 && header->_base_archive_name_offset == 0)) {
fail_continue("Default base archive not set correct");
return false;
}
if (header->_base_archive_name_size == 0 &&
header->_base_archive_path_offset == 0) {
header->_base_archive_name_offset == 0) {
*base_archive_name = Arguments::get_default_shared_archive_path();
} else {
// read the base archive name
@@ -1217,14 +1217,14 @@ bool FileMapInfo::init_from_file(int fd) {
return false;
}

unsigned int base_offset = header()->base_archive_path_offset();
unsigned int base_offset = header()->base_archive_name_offset();
unsigned int name_size = header()->base_archive_name_size();
unsigned int header_size = header()->header_size();
if (base_offset != 0 && name_size != 0) {
if (header_size != base_offset + name_size) {
log_info(cds)("_header_size: " UINT32_FORMAT, header_size);
log_info(cds)("base_archive_name_size: " UINT32_FORMAT, name_size);
log_info(cds)("base_archive_path_offset: " UINT32_FORMAT, base_offset);
log_info(cds)("base_archive_name_offset: " UINT32_FORMAT, base_offset);
FileMapInfo::fail_continue("The shared archive file has an incorrect header size.");
return false;
}
@@ -243,14 +243,14 @@ class FileMapHeader: private CDSFileMapHeaderBase {
int crc() const { return _generic_header._crc; }
int version() const { return _generic_header._version; }
unsigned int header_size() const { return _generic_header._header_size; }
unsigned int base_archive_path_offset() const { return _generic_header._base_archive_path_offset; }
unsigned int base_archive_name_offset() const { return _generic_header._base_archive_name_offset; }
unsigned int base_archive_name_size() const { return _generic_header._base_archive_name_size; }

void set_magic(unsigned int m) { _generic_header._magic = m; }
void set_crc(int crc_value) { _generic_header._crc = crc_value; }
void set_version(int v) { _generic_header._version = v; }
void set_header_size(unsigned int s) { _generic_header._header_size = s; }
void set_base_archive_path_offset(unsigned int s) { _generic_header._base_archive_path_offset = s; }
void set_base_archive_name_offset(unsigned int s) { _generic_header._base_archive_name_offset = s; }
void set_base_archive_name_size(unsigned int s) { _generic_header._base_archive_name_size = s; }

size_t core_region_alignment() const { return _core_region_alignment; }
@@ -313,7 +313,7 @@ class FileMapHeader: private CDSFileMapHeaderBase {
}

void populate(FileMapInfo *info, size_t core_region_alignment, size_t header_size,
size_t base_archive_name_size, size_t base_archive_path_offset);
size_t base_archive_name_size, size_t base_archive_name_offset);
static bool is_valid_region(int region) {
return (0 <= region && region < NUM_CDS_REGIONS);
}
@@ -67,12 +67,12 @@ typedef struct GenericCDSFileMapHeader {
int _crc; // header crc checksum
int _version; // CURRENT_CDS_ARCHIVE_VERSION of the jdk that dumped the this archive
unsigned int _header_size; // total size of the header, in bytes
unsigned int _base_archive_path_offset; // offset where the base archive name is stored
unsigned int _base_archive_name_offset; // offset where the base archive name is stored
// static archive: 0
// dynamic archive:
// 0 for default base archive
// non-zero for non-default base archive
// (char*)this + _base_archive_path_offset
// (char*)this + _base_archive_name_offset
// points to a 0-terminated string for the base archive name
unsigned int _base_archive_name_size; // size of base archive name including ending '\0'
// static: 0
@@ -222,15 +222,15 @@ public static void main(String... args) throws Exception {
CDSArchiveUtils.modifyRegionContentRandomly(copiedJsa);
testAndCheck(verifyExecArgs);

// modify _base_archive_path_offet to non-zero
System.out.println("\n8. modify _base_archive_path_offset to non-zero\n");
String baseArchivePathOffsetName = startNewArchive("base-arhive-path-offset");
copiedJsa = CDSArchiveUtils.copyArchiveFile(orgJsaFile, baseArchivePathOffsetName);
int baseArchivePathOffset = CDSArchiveUtils.baseArchivePathOffset(copiedJsa);
System.out.println(" baseArchivePathOffset = " + baseArchivePathOffset);
CDSArchiveUtils.writeData(copiedJsa, CDSArchiveUtils.offsetBaseArchivePathOffset(), 1024);
baseArchivePathOffset = CDSArchiveUtils.baseArchivePathOffset(copiedJsa);
System.out.println("new baseArchivePathOffset = " + baseArchivePathOffset);
// modify _base_archive_name_offet to non-zero
System.out.println("\n8. modify _base_archive_name_offset to non-zero\n");
String baseArchiveNameOffsetName = startNewArchive("base-arhive-path-offset");
copiedJsa = CDSArchiveUtils.copyArchiveFile(orgJsaFile, baseArchiveNameOffsetName);
int baseArchiveNameOffset = CDSArchiveUtils.baseArchiveNameOffset(copiedJsa);
System.out.println(" baseArchiveNameOffset = " + baseArchiveNameOffset);
CDSArchiveUtils.writeData(copiedJsa, CDSArchiveUtils.offsetBaseArchiveNameOffset(), 1024);
baseArchiveNameOffset = CDSArchiveUtils.baseArchiveNameOffset(copiedJsa);
System.out.println("new baseArchiveNameOffset = " + baseArchiveNameOffset);
testAndCheck(verifyExecArgs);
}
}
@@ -112,31 +112,31 @@ private static void doTest(String baseArchiveName, String topArchiveName) throws
CDSArchiveUtils.modifyHeaderIntField(copiedJsa, CDSArchiveUtils.offsetHeaderSize(), (int)copiedJsa.length() + 1024);
runTwo(baseArchiveName, largerHeaderSize,
appJar, mainClass, 1,
new String[] {"_header_size should be equal to _base_archive_path_offset plus _base_archive_name_size",
new String[] {"_header_size should be equal to _base_archive_name_offset plus _base_archive_name_size",
"Unable to use shared archive"});

// 3. Make base archive path offset beyond of header size
System.out.println("\n3. Make base archive path offset beyond of header size.");
String wrongBaseArchivePathOffset = getNewArchiveName("wrongBaseArchivePathOffset");
copiedJsa = CDSArchiveUtils.copyArchiveFile(jsa, wrongBaseArchivePathOffset);
String wrongBaseArchiveNameOffset = getNewArchiveName("wrongBaseArchiveNameOffset");
copiedJsa = CDSArchiveUtils.copyArchiveFile(jsa, wrongBaseArchiveNameOffset);
int fileHeaderSize = (int)CDSArchiveUtils.fileHeaderSize(copiedJsa);
int baseArchivePathOffset = CDSArchiveUtils.baseArchivePathOffset(copiedJsa);
CDSArchiveUtils.modifyHeaderIntField(copiedJsa, CDSArchiveUtils.offsetBaseArchivePathOffset(), baseArchivePathOffset + 1024);
runTwo(baseArchiveName, wrongBaseArchivePathOffset,
int baseArchiveNameOffset = CDSArchiveUtils.baseArchiveNameOffset(copiedJsa);
CDSArchiveUtils.modifyHeaderIntField(copiedJsa, CDSArchiveUtils.offsetBaseArchiveNameOffset(), baseArchiveNameOffset + 1024);
runTwo(baseArchiveName, wrongBaseArchiveNameOffset,
appJar, mainClass, 1,
new String[] {"_header_size should be equal to _base_archive_path_offset plus _base_archive_name_size",
new String[] {"_header_size should be equal to _base_archive_name_offset plus _base_archive_name_size",
"The shared archive file has an incorrect header size",
"Unable to use shared archive"});

// 4. Make base archive path offset points to middle of name size
System.out.println("\n4. Make base archive path offset points to middle of name size");
String wrongBasePathOffset = getNewArchiveName("wrongBasePathOffset");
copiedJsa = CDSArchiveUtils.copyArchiveFile(jsa, wrongBasePathOffset);
String wrongBaseNameOffset = getNewArchiveName("wrongBaseNameOffset");
copiedJsa = CDSArchiveUtils.copyArchiveFile(jsa, wrongBaseNameOffset);
int baseArchiveNameSize = CDSArchiveUtils.baseArchiveNameSize(copiedJsa);
baseArchivePathOffset = CDSArchiveUtils.baseArchivePathOffset(copiedJsa);
CDSArchiveUtils.modifyHeaderIntField(copiedJsa, baseArchivePathOffset,
baseArchivePathOffset + baseArchiveNameSize/2);
runTwo(baseArchiveName, wrongBasePathOffset,
baseArchiveNameOffset = CDSArchiveUtils.baseArchiveNameOffset(copiedJsa);
CDSArchiveUtils.modifyHeaderIntField(copiedJsa, baseArchiveNameOffset,
baseArchiveNameOffset + baseArchiveNameSize/2);
runTwo(baseArchiveName, wrongBaseNameOffset,
appJar, mainClass, 1,
new String[] {"An error has occurred while processing the shared archive file.",
"Header checksum verification failed",
@@ -146,9 +146,9 @@ private static void doTest(String baseArchiveName, String topArchiveName) throws
System.out.println("\n5. Make base archive name not terminated with '\0'");
String wrongBaseName = getNewArchiveName("wrongBaseName");
copiedJsa = CDSArchiveUtils.copyArchiveFile(jsa, wrongBaseName);
baseArchivePathOffset = CDSArchiveUtils.baseArchivePathOffset(copiedJsa);
baseArchiveNameOffset = CDSArchiveUtils.baseArchiveNameOffset(copiedJsa);
baseArchiveNameSize = CDSArchiveUtils.baseArchiveNameSize(copiedJsa);
long offset = baseArchivePathOffset + baseArchiveNameSize - 1; // end of line
long offset = baseArchiveNameOffset + baseArchiveNameSize - 1; // end of line
CDSArchiveUtils.writeData(copiedJsa, offset, new byte[] {(byte)'X'});

runTwo(baseArchiveName, wrongBaseName,
@@ -160,9 +160,9 @@ private static void doTest(String baseArchiveName, String topArchiveName) throws
System.out.println("\n6. Modify base archive name to a file that doesn't exist");
String wrongBaseName2 = getNewArchiveName("wrongBaseName2");
copiedJsa = CDSArchiveUtils.copyArchiveFile(jsa, wrongBaseName2);
baseArchivePathOffset = CDSArchiveUtils.baseArchivePathOffset(copiedJsa);
baseArchiveNameOffset = CDSArchiveUtils.baseArchiveNameOffset(copiedJsa);
baseArchiveNameSize = CDSArchiveUtils.baseArchiveNameSize(copiedJsa);
offset = baseArchivePathOffset + baseArchiveNameSize - 2; // the "a" in ".jsa"
offset = baseArchiveNameOffset + baseArchiveNameSize - 2; // the "a" in ".jsa"
CDSArchiveUtils.writeData(copiedJsa, offset, new byte[] {(byte)'b'}); // .jsa -> .jsb

// Make sure it doesn't exist