< prev index next >

src/hotspot/share/prims/cdsoffsets.cpp

Print this page


  27 #if INCLUDE_CDS
  28 #include "runtime/os.hpp"
  29 #include "memory/filemap.hpp"
  30 #include "memory/allocation.hpp"
  31 #include "memory/allocation.inline.hpp"
  32 #include "prims/cdsoffsets.hpp"
  33 
  34 CDSOffsets::CDSOffsets(const char* name, int offset, CDSOffsets* next) {
  35   _name = NEW_C_HEAP_ARRAY(char, strlen(name) + 1, mtInternal);
  36   strcpy(_name, name);
  37   _offset = offset;
  38   _next = next;
  39 }
  40 
  41 CDSOffsets* CDSOffsets::_all = NULL;
  42 #define ADD_NEXT(list, name, value) \
  43   list->add_end(new CDSOffsets(name, value, NULL))
  44 
  45 #define CREATE_OFFSET_MAPS                                                                                  \
  46     _all = new CDSOffsets("size_t_size", sizeof(size_t), NULL);                                             \
  47     ADD_NEXT(_all, "FileMapHeader::_magic", offset_of(FileMapInfo::FileMapHeader, _magic));                 \
  48     ADD_NEXT(_all, "FileMapHeader::_crc", offset_of(FileMapInfo::FileMapHeader, _crc));                     \
  49     ADD_NEXT(_all, "FileMapHeader::_version", offset_of(FileMapInfo::FileMapHeader, _version));             \
  50     ADD_NEXT(_all, "FileMapHeader::_space[0]", offset_of(FileMapInfo::FileMapHeader, _space));              \
  51     ADD_NEXT(_all, "space_info::_crc", offset_of(FileMapInfo::FileMapHeader::space_info, _crc));            \
  52     ADD_NEXT(_all, "space_info::_used", offset_of(FileMapInfo::FileMapHeader::space_info, _used));          \
  53     ADD_NEXT(_all, "FileMapHeader::_paths_misc_info_size", offset_of(FileMapInfo::FileMapHeader, _paths_misc_info_size)); \
  54     ADD_NEXT(_all, "file_header_size", sizeof(FileMapInfo::FileMapHeader));                                 \
  55     ADD_NEXT(_all, "space_info_size", sizeof(FileMapInfo::FileMapHeader::space_info));
  56 
  57 int CDSOffsets::find_offset(const char* name) {
  58   if (_all == NULL) {
  59     CREATE_OFFSET_MAPS
  60   }
  61   CDSOffsets* it = _all;
  62   while(it) {
  63     if (!strcmp(name, it->get_name())) {
  64       return it->get_offset();
  65     }
  66     it = it->next();
  67   }
  68   return -1; // not found
  69 }
  70 
  71 void CDSOffsets::add_end(CDSOffsets* n) {
  72   CDSOffsets* p = this;
  73   while(p && p->_next) { p = p->_next; }
  74   p->_next = n;
  75 }


  27 #if INCLUDE_CDS
  28 #include "runtime/os.hpp"
  29 #include "memory/filemap.hpp"
  30 #include "memory/allocation.hpp"
  31 #include "memory/allocation.inline.hpp"
  32 #include "prims/cdsoffsets.hpp"
  33 
  34 CDSOffsets::CDSOffsets(const char* name, int offset, CDSOffsets* next) {
  35   _name = NEW_C_HEAP_ARRAY(char, strlen(name) + 1, mtInternal);
  36   strcpy(_name, name);
  37   _offset = offset;
  38   _next = next;
  39 }
  40 
  41 CDSOffsets* CDSOffsets::_all = NULL;
  42 #define ADD_NEXT(list, name, value) \
  43   list->add_end(new CDSOffsets(name, value, NULL))
  44 
  45 #define CREATE_OFFSET_MAPS                                                                  \
  46     _all = new CDSOffsets("size_t_size", sizeof(size_t), NULL);                             \
  47     ADD_NEXT(_all, "FileMapHeader::_magic", offset_of(FileMapHeader, _magic));              \
  48     ADD_NEXT(_all, "FileMapHeader::_crc", offset_of(FileMapHeader, _crc));                  \
  49     ADD_NEXT(_all, "FileMapHeader::_version", offset_of(FileMapHeader, _version));          \
  50     ADD_NEXT(_all, "FileMapHeader::_space[0]", offset_of(FileMapHeader, _space));           \
  51     ADD_NEXT(_all, "CDSFileMapRegion::_crc", offset_of(CDSFileMapRegion, _crc));            \
  52     ADD_NEXT(_all, "CDSFileMapRegion::_used", offset_of(CDSFileMapRegion, _used));          \
  53     ADD_NEXT(_all, "FileMapHeader::_paths_misc_info_size", offset_of(FileMapHeader, _paths_misc_info_size)); \
  54     ADD_NEXT(_all, "file_header_size", sizeof(FileMapHeader));                              \
  55     ADD_NEXT(_all, "CDSFileMapRegion_size", sizeof(CDSFileMapRegion));
  56 
  57 int CDSOffsets::find_offset(const char* name) {
  58   if (_all == NULL) {
  59     CREATE_OFFSET_MAPS
  60   }
  61   CDSOffsets* it = _all;
  62   while(it) {
  63     if (!strcmp(name, it->get_name())) {
  64       return it->get_offset();
  65     }
  66     it = it->next();
  67   }
  68   return -1; // not found
  69 }
  70 
  71 void CDSOffsets::add_end(CDSOffsets* n) {
  72   CDSOffsets* p = this;
  73   while(p && p->_next) { p = p->_next; }
  74   p->_next = n;
  75 }
< prev index next >