Path: blob/master/src/hotspot/share/cds/cdsoffsets.cpp
41144 views
/*1* Copyright (c) 2014, 2021, 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#include "precompiled.hpp"25#include "cds/cdsoffsets.hpp"26#include "cds/dynamicArchive.hpp"27#include "cds/filemap.hpp"28#include "runtime/os.hpp"29#include "memory/allocation.hpp"30#include "memory/allocation.inline.hpp"31#include "utilities/macros.hpp"3233CDSOffsets::CDSOffsets(const char* name, int offset, CDSOffsets* next) {34_name = NEW_C_HEAP_ARRAY(char, strlen(name) + 1, mtInternal);35strcpy(_name, name);36_offset = offset;37_next = next;38}3940CDSOffsets* CDSOffsets::_all = NULL;41#define ADD_NEXT(list, name, value) \42list->add_end(new CDSOffsets(name, value, NULL))4344#define CREATE_OFFSET_MAPS \45_all = new CDSOffsets("size_t_size", sizeof(size_t), NULL); \46ADD_NEXT(_all, "int_size", sizeof(int)); \47ADD_NEXT(_all, "FileMapHeader::_magic", offset_of(FileMapHeader, _magic)); \48ADD_NEXT(_all, "FileMapHeader::_crc", offset_of(FileMapHeader, _crc)); \49ADD_NEXT(_all, "FileMapHeader::_version", offset_of(FileMapHeader, _version)); \50ADD_NEXT(_all, "FileMapHeader::_jvm_ident", offset_of(FileMapHeader, _jvm_ident)); \51ADD_NEXT(_all, "FileMapHeader::_space[0]", offset_of(FileMapHeader, _space)); \52ADD_NEXT(_all, "CDSFileMapRegion::_crc", offset_of(CDSFileMapRegion, _crc)); \53ADD_NEXT(_all, "CDSFileMapRegion::_used", offset_of(CDSFileMapRegion, _used)); \54ADD_NEXT(_all, "file_header_size", sizeof(FileMapHeader)); \55ADD_NEXT(_all, "DynamicArchiveHeader::_base_region_crc", offset_of(DynamicArchiveHeader, _base_region_crc)); \56ADD_NEXT(_all, "CDSFileMapRegion_size", sizeof(CDSFileMapRegion));5758int CDSOffsets::find_offset(const char* name) {59if (_all == NULL) {60CREATE_OFFSET_MAPS61}62CDSOffsets* it = _all;63while(it) {64if (!strcmp(name, it->get_name())) {65return it->get_offset();66}67it = it->next();68}69return -1; // not found70}7172void CDSOffsets::add_end(CDSOffsets* n) {73CDSOffsets* p = this;74while(p && p->_next) { p = p->_next; }75p->_next = n;76}777879