src/hotspot/share/memory/metaspaceShared.cpp
changeset 48794 ea0d0781c63c
parent 48383 d6388b652504
child 48962 88ad6c676c87
equal deleted inserted replaced
48793:b9a29dfaaeb2 48794:ea0d0781c63c
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   744     }
   744     }
   745   }
   745   }
   746 }
   746 }
   747 
   747 
   748 bool MetaspaceShared::is_valid_shared_method(const Method* m) {
   748 bool MetaspaceShared::is_valid_shared_method(const Method* m) {
   749   assert(is_in_shared_space(m), "must be");
   749   assert(is_in_shared_metaspace(m), "must be");
   750   return CppVtableCloner<Method>::is_valid_shared_object(m);
   750   return CppVtableCloner<Method>::is_valid_shared_object(m);
   751 }
   751 }
   752 
   752 
   753 // Closure for serializing initialization data out to a data area to be
   753 // Closure for serializing initialization data out to a data area to be
   754 // written to the shared file.
   754 // written to the shared file.
  1817   }
  1817   }
  1818 
  1818 
  1819   bool reading() const { return true; }
  1819   bool reading() const { return true; }
  1820 };
  1820 };
  1821 
  1821 
  1822 // Return true if given address is in the mapped shared space.
       
  1823 bool MetaspaceShared::is_in_shared_space(const void* p) {
       
  1824   return UseSharedSpaces && FileMapInfo::current_info()->is_in_shared_space(p);
       
  1825 }
       
  1826 
       
  1827 // Return true if given address is in the misc data region
  1822 // Return true if given address is in the misc data region
  1828 bool MetaspaceShared::is_in_shared_region(const void* p, int idx) {
  1823 bool MetaspaceShared::is_in_shared_region(const void* p, int idx) {
  1829   return UseSharedSpaces && FileMapInfo::current_info()->is_in_shared_region(p, idx);
  1824   return UseSharedSpaces && FileMapInfo::current_info()->is_in_shared_region(p, idx);
  1830 }
  1825 }
  1831 
  1826 
  1855   if (!shared_rs.is_reserved()) return false;
  1850   if (!shared_rs.is_reserved()) return false;
  1856 #endif
  1851 #endif
  1857 
  1852 
  1858   assert(!DumpSharedSpaces, "Should not be called with DumpSharedSpaces");
  1853   assert(!DumpSharedSpaces, "Should not be called with DumpSharedSpaces");
  1859 
  1854 
  1860   char* _ro_base = NULL;
  1855   char* ro_base = NULL; char* ro_top;
  1861   char* _rw_base = NULL;
  1856   char* rw_base = NULL; char* rw_top;
  1862   char* _mc_base = NULL;
  1857   char* mc_base = NULL; char* mc_top;
  1863   char* _md_base = NULL;
  1858   char* md_base = NULL; char* md_top;
  1864   char* _od_base = NULL;
  1859   char* od_base = NULL; char* od_top;
  1865 
  1860 
  1866   // Map each shared region
  1861   // Map each shared region
  1867   if ((_mc_base = mapinfo->map_region(mc)) != NULL &&
  1862   if ((mc_base = mapinfo->map_region(mc, &mc_top)) != NULL &&
  1868       mapinfo->verify_region_checksum(mc) &&
  1863       (rw_base = mapinfo->map_region(rw, &rw_top)) != NULL &&
  1869       (_rw_base = mapinfo->map_region(rw)) != NULL &&
  1864       (ro_base = mapinfo->map_region(ro, &ro_top)) != NULL &&
  1870       mapinfo->verify_region_checksum(rw) &&
  1865       (md_base = mapinfo->map_region(md, &md_top)) != NULL &&
  1871       (_ro_base = mapinfo->map_region(ro)) != NULL &&
  1866       (od_base = mapinfo->map_region(od, &od_top)) != NULL &&
  1872       mapinfo->verify_region_checksum(ro) &&
       
  1873       (_md_base = mapinfo->map_region(md)) != NULL &&
       
  1874       mapinfo->verify_region_checksum(md) &&
       
  1875       (_od_base = mapinfo->map_region(od)) != NULL &&
       
  1876       mapinfo->verify_region_checksum(od) &&
       
  1877       (image_alignment == (size_t)os::vm_allocation_granularity()) &&
  1867       (image_alignment == (size_t)os::vm_allocation_granularity()) &&
  1878       mapinfo->validate_classpath_entry_table()) {
  1868       mapinfo->validate_classpath_entry_table()) {
  1879     // Success (no need to do anything)
  1869     // Success -- set up MetaspaceObj::_shared_metaspace_{base,top} for
       
  1870     // fast checking in MetaspaceShared::is_in_shared_metaspace() and
       
  1871     // MetaspaceObj::is_shared().
       
  1872     //
       
  1873     // We require that mc->rw->ro->md->od to be laid out consecutively, with no
       
  1874     // gaps between them. That way, we can ensure that the OS won't be able to
       
  1875     // allocate any new memory spaces inside _shared_metaspace_{base,top}, which
       
  1876     // would mess up the simple comparision in MetaspaceShared::is_in_shared_metaspace().
       
  1877     assert(mc_base < ro_base && mc_base < rw_base && mc_base < md_base && mc_base < od_base, "must be");
       
  1878     assert(od_top  > ro_top  && od_top  > rw_top  && od_top  > md_top  && od_top  > mc_top , "must be");
       
  1879     assert(mc_top == rw_base, "must be");
       
  1880     assert(rw_top == ro_base, "must be");
       
  1881     assert(ro_top == md_base, "must be");
       
  1882     assert(md_top == od_base, "must be");
       
  1883 
       
  1884     MetaspaceObj::_shared_metaspace_base = (void*)mc_base;
       
  1885     MetaspaceObj::_shared_metaspace_top  = (void*)od_top;
  1880     return true;
  1886     return true;
  1881   } else {
  1887   } else {
  1882     // If there was a failure in mapping any of the spaces, unmap the ones
  1888     // If there was a failure in mapping any of the spaces, unmap the ones
  1883     // that succeeded
  1889     // that succeeded
  1884     if (_ro_base != NULL) mapinfo->unmap_region(ro);
  1890     if (ro_base != NULL) mapinfo->unmap_region(ro);
  1885     if (_rw_base != NULL) mapinfo->unmap_region(rw);
  1891     if (rw_base != NULL) mapinfo->unmap_region(rw);
  1886     if (_mc_base != NULL) mapinfo->unmap_region(mc);
  1892     if (mc_base != NULL) mapinfo->unmap_region(mc);
  1887     if (_md_base != NULL) mapinfo->unmap_region(md);
  1893     if (md_base != NULL) mapinfo->unmap_region(md);
  1888     if (_od_base != NULL) mapinfo->unmap_region(od);
  1894     if (od_base != NULL) mapinfo->unmap_region(od);
  1889 #ifndef _WINDOWS
  1895 #ifndef _WINDOWS
  1890     // Release the entire mapped region
  1896     // Release the entire mapped region
  1891     shared_rs.release();
  1897     shared_rs.release();
  1892 #endif
  1898 #endif
  1893     // If -Xshare:on is specified, print out the error message and exit VM,
  1899     // If -Xshare:on is specified, print out the error message and exit VM,