1 #ifdef USE_PRAGMA_IDENT_SRC
   2 #pragma ident "@(#)restore.cpp  1.14 07/05/05 17:05:44 JVM"
   3 #endif
   4 /*
   5  * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  
  26  */
  27 
  28 # include "incls/_precompiled.incl"
  29 # include "incls/_restore.cpp.incl"
  30 
  31 
  32 // Closure for serializing initialization data in from a data area
  33 // (oop_array) read from the shared file.
  34 
  35 class ReadClosure : public SerializeOopClosure {
  36 private:
  37   oop** _oop_array;
  38 
  39   inline oop nextOop() {
  40     return *(*_oop_array)++;
  41   }
  42 
  43 public:
  44   ReadClosure(oop** oop_array) { _oop_array = oop_array; }
  45 
  46   void do_oop(oop* p) {
  47     assert(SharedSkipVerify || *p == NULL || *p == Universe::klassKlassObj(),
  48            "initializing previously initialized oop.");
  49     oop obj = nextOop();
  50     assert(SharedSkipVerify || (intptr_t)obj >= 0 || (intptr_t)obj < -100,
  51            "hit tag while initializing oops.");
  52     assert(SharedSkipVerify || obj->is_oop_or_null(), "invalid oop");
  53     *p = obj;
  54   }
  55 
  56   void do_oop(narrowOop* p) { ShouldNotReachHere(); }
  57 
  58   void do_ptr(void** p) {
  59     assert(*p == NULL, "initializing previous initialized pointer.");
  60     void* obj = nextOop();
  61     assert((intptr_t)obj >= 0 || (intptr_t)obj < -100,
  62            "hit tag while initializing ptrs.");
  63     *p = obj;
  64   }
  65 
  66   void do_ptr(HeapWord** p) { do_ptr((void **) p); }
  67 
  68   void do_int(int* p) {
  69     *p = (int)(intptr_t)nextOop();
  70   }
  71 
  72   void do_size_t(size_t* p) {
  73     // Assumes that size_t and pointers are the same size.
  74     *p = (size_t)nextOop();
  75   }
  76 
  77   void do_tag(int tag) {
  78     int old_tag;
  79     do_int(&old_tag);
  80     FileMapInfo::assert_mark(tag == old_tag);
  81   }
  82 
  83   void do_region(u_char* start, size_t size) {
  84     assert((intptr_t)start % sizeof(oop) == 0, "bad alignment");
  85     assert(size % sizeof(oop) == 0, "bad size");
  86     do_tag((int)size);
  87     while (size > 0) {
  88       *(oop*)start = nextOop();
  89       start += sizeof(oop);
  90       size -= sizeof(oop);
  91     }
  92   }
  93 
  94   bool reading() const { return true; }
  95 };
  96 
  97 
  98 // Read the oop and miscellaneous data from the shared file, and
  99 // serialize it out to its various destinations.
 100 
 101 void CompactingPermGenGen::initialize_oops() {
 102   FileMapInfo *mapinfo = FileMapInfo::current_info();
 103 
 104   char* buffer = mapinfo->region_base(md);
 105 
 106   // Skip over (reserve space for) a list of addresses of C++ vtables
 107   // for Klass objects.  They get filled in later.
 108 
 109   // Skip over (reserve space for) dummy C++ vtables Klass objects.
 110   // They are used as is.
 111 
 112   void** vtbl_list = (void**)buffer;
 113   buffer += vtbl_list_size * sizeof(void*);
 114   intptr_t vtable_size = *(intptr_t*)buffer;
 115   buffer += sizeof(intptr_t);
 116   buffer += vtable_size;
 117 
 118   // Create the symbol table using the bucket array at this spot in the
 119   // misc data space.  Since the symbol table is often modified, this
 120   // region (of mapped pages) will be copy-on-write.
 121 
 122   int symbolTableLen = *(intptr_t*)buffer;
 123   buffer += sizeof(intptr_t);
 124   int number_of_entries = *(intptr_t*)buffer;
 125   buffer += sizeof(intptr_t);
 126   SymbolTable::create_table((HashtableBucket*)buffer, symbolTableLen,
 127                             number_of_entries);
 128   buffer += symbolTableLen;
 129 
 130   // Create the string table using the bucket array at this spot in the
 131   // misc data space.  Since the string table is often modified, this
 132   // region (of mapped pages) will be copy-on-write.
 133 
 134   int stringTableLen = *(intptr_t*)buffer;
 135   buffer += sizeof(intptr_t);
 136   number_of_entries = *(intptr_t*)buffer;
 137   buffer += sizeof(intptr_t);
 138   StringTable::create_table((HashtableBucket*)buffer, stringTableLen,
 139                             number_of_entries);
 140   buffer += stringTableLen;
 141 
 142   // Create the shared dictionary using the bucket array at this spot in
 143   // the misc data space.  Since the shared dictionary table is never
 144   // modified, this region (of mapped pages) will be (effectively, if
 145   // not explicitly) read-only.
 146 
 147   int sharedDictionaryLen = *(intptr_t*)buffer;
 148   buffer += sizeof(intptr_t);
 149   number_of_entries = *(intptr_t*)buffer;
 150   buffer += sizeof(intptr_t);
 151   SystemDictionary::set_shared_dictionary((HashtableBucket*)buffer,
 152                                           sharedDictionaryLen,
 153                                           number_of_entries);
 154   buffer += sharedDictionaryLen;
 155 
 156   // Create the package info table using the bucket array at this spot in
 157   // the misc data space.  Since the package info table is never
 158   // modified, this region (of mapped pages) will be (effectively, if
 159   // not explicitly) read-only.
 160 
 161   int pkgInfoLen = *(intptr_t*)buffer;
 162   buffer += sizeof(intptr_t);
 163   number_of_entries = *(intptr_t*)buffer;
 164   buffer += sizeof(intptr_t);
 165   ClassLoader::create_package_info_table((HashtableBucket*)buffer, pkgInfoLen,
 166                                          number_of_entries);
 167   buffer += pkgInfoLen;
 168   ClassLoader::verify();
 169 
 170   // The following data in the shared misc data region are the linked
 171   // list elements (HashtableEntry objects) for the symbol table, string
 172   // table, and shared dictionary.  The heap objects refered to by the
 173   // symbol table, string table, and shared dictionary are permanent and
 174   // unmovable.  Since new entries added to the string and symbol tables
 175   // are always added at the beginning of the linked lists, THESE LINKED
 176   // LIST ELEMENTS ARE READ-ONLY.
 177 
 178   int len = *(intptr_t*)buffer; // skip over symbol table entries
 179   buffer += sizeof(intptr_t);
 180   buffer += len;
 181 
 182   len = *(intptr_t*)buffer;     // skip over string table entries
 183   buffer += sizeof(intptr_t);
 184   buffer += len;
 185 
 186   len = *(intptr_t*)buffer;     // skip over shared dictionary entries
 187   buffer += sizeof(intptr_t);
 188   buffer += len;
 189 
 190   len = *(intptr_t*)buffer;     // skip over package info table entries
 191   buffer += sizeof(intptr_t);
 192   buffer += len;
 193 
 194   len = *(intptr_t*)buffer;     // skip over package info table char[] arrays.
 195   buffer += sizeof(intptr_t);
 196   buffer += len;
 197 
 198   oop* oop_array = (oop*)buffer;
 199   ReadClosure rc(&oop_array);
 200   serialize_oops(&rc);
 201 }