src/share/vm/memory/restore.cpp

changeset 435
a61af66fc99e
child 548
ba764ed4b6f2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/memory/restore.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,196 @@
     1.4 +/*
     1.5 + * Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +# include "incls/_precompiled.incl"
    1.29 +# include "incls/_restore.cpp.incl"
    1.30 +
    1.31 +
    1.32 +// Closure for serializing initialization data in from a data area
    1.33 +// (oop_array) read from the shared file.
    1.34 +
    1.35 +class ReadClosure : public SerializeOopClosure {
    1.36 +private:
    1.37 +  oop** _oop_array;
    1.38 +
    1.39 +  inline oop nextOop() {
    1.40 +    return *(*_oop_array)++;
    1.41 +  }
    1.42 +
    1.43 +public:
    1.44 +  ReadClosure(oop** oop_array) { _oop_array = oop_array; }
    1.45 +
    1.46 +  void do_oop(oop* p) {
    1.47 +    assert(SharedSkipVerify || *p == NULL || *p == Universe::klassKlassObj(),
    1.48 +           "initializing previously initialized oop.");
    1.49 +    oop obj = nextOop();
    1.50 +    assert(SharedSkipVerify || (intptr_t)obj >= 0 || (intptr_t)obj < -100,
    1.51 +           "hit tag while initializing oops.");
    1.52 +    assert(SharedSkipVerify || obj->is_oop_or_null(), "invalid oop");
    1.53 +    *p = obj;
    1.54 +  }
    1.55 +
    1.56 +  void do_ptr(void** p) {
    1.57 +    assert(*p == NULL, "initializing previous initialized pointer.");
    1.58 +    void* obj = nextOop();
    1.59 +    assert((intptr_t)obj >= 0 || (intptr_t)obj < -100,
    1.60 +           "hit tag while initializing ptrs.");
    1.61 +    *p = obj;
    1.62 +  }
    1.63 +
    1.64 +  void do_ptr(HeapWord** p) { do_ptr((void **) p); }
    1.65 +
    1.66 +  void do_int(int* p) {
    1.67 +    *p = (int)(intptr_t)nextOop();
    1.68 +  }
    1.69 +
    1.70 +  void do_size_t(size_t* p) {
    1.71 +    // Assumes that size_t and pointers are the same size.
    1.72 +    *p = (size_t)nextOop();
    1.73 +  }
    1.74 +
    1.75 +  void do_tag(int tag) {
    1.76 +    int old_tag;
    1.77 +    do_int(&old_tag);
    1.78 +    FileMapInfo::assert_mark(tag == old_tag);
    1.79 +  }
    1.80 +
    1.81 +  void do_region(u_char* start, size_t size) {
    1.82 +    assert((intptr_t)start % sizeof(oop) == 0, "bad alignment");
    1.83 +    assert(size % sizeof(oop) == 0, "bad size");
    1.84 +    do_tag((int)size);
    1.85 +    while (size > 0) {
    1.86 +      *(oop*)start = nextOop();
    1.87 +      start += sizeof(oop);
    1.88 +      size -= sizeof(oop);
    1.89 +    }
    1.90 +  }
    1.91 +
    1.92 +  bool reading() const { return true; }
    1.93 +};
    1.94 +
    1.95 +
    1.96 +// Read the oop and miscellaneous data from the shared file, and
    1.97 +// serialize it out to its various destinations.
    1.98 +
    1.99 +void CompactingPermGenGen::initialize_oops() {
   1.100 +  FileMapInfo *mapinfo = FileMapInfo::current_info();
   1.101 +
   1.102 +  char* buffer = mapinfo->region_base(md);
   1.103 +
   1.104 +  // Skip over (reserve space for) a list of addresses of C++ vtables
   1.105 +  // for Klass objects.  They get filled in later.
   1.106 +
   1.107 +  // Skip over (reserve space for) dummy C++ vtables Klass objects.
   1.108 +  // They are used as is.
   1.109 +
   1.110 +  void** vtbl_list = (void**)buffer;
   1.111 +  buffer += vtbl_list_size * sizeof(void*);
   1.112 +  intptr_t vtable_size = *(intptr_t*)buffer;
   1.113 +  buffer += sizeof(intptr_t);
   1.114 +  buffer += vtable_size;
   1.115 +
   1.116 +  // Create the symbol table using the bucket array at this spot in the
   1.117 +  // misc data space.  Since the symbol table is often modified, this
   1.118 +  // region (of mapped pages) will be copy-on-write.
   1.119 +
   1.120 +  int symbolTableLen = *(intptr_t*)buffer;
   1.121 +  buffer += sizeof(intptr_t);
   1.122 +  int number_of_entries = *(intptr_t*)buffer;
   1.123 +  buffer += sizeof(intptr_t);
   1.124 +  SymbolTable::create_table((HashtableBucket*)buffer, symbolTableLen,
   1.125 +                            number_of_entries);
   1.126 +  buffer += symbolTableLen;
   1.127 +
   1.128 +  // Create the string table using the bucket array at this spot in the
   1.129 +  // misc data space.  Since the string table is often modified, this
   1.130 +  // region (of mapped pages) will be copy-on-write.
   1.131 +
   1.132 +  int stringTableLen = *(intptr_t*)buffer;
   1.133 +  buffer += sizeof(intptr_t);
   1.134 +  number_of_entries = *(intptr_t*)buffer;
   1.135 +  buffer += sizeof(intptr_t);
   1.136 +  StringTable::create_table((HashtableBucket*)buffer, stringTableLen,
   1.137 +                            number_of_entries);
   1.138 +  buffer += stringTableLen;
   1.139 +
   1.140 +  // Create the shared dictionary using the bucket array at this spot in
   1.141 +  // the misc data space.  Since the shared dictionary table is never
   1.142 +  // modified, this region (of mapped pages) will be (effectively, if
   1.143 +  // not explicitly) read-only.
   1.144 +
   1.145 +  int sharedDictionaryLen = *(intptr_t*)buffer;
   1.146 +  buffer += sizeof(intptr_t);
   1.147 +  number_of_entries = *(intptr_t*)buffer;
   1.148 +  buffer += sizeof(intptr_t);
   1.149 +  SystemDictionary::set_shared_dictionary((HashtableBucket*)buffer,
   1.150 +                                          sharedDictionaryLen,
   1.151 +                                          number_of_entries);
   1.152 +  buffer += sharedDictionaryLen;
   1.153 +
   1.154 +  // Create the package info table using the bucket array at this spot in
   1.155 +  // the misc data space.  Since the package info table is never
   1.156 +  // modified, this region (of mapped pages) will be (effectively, if
   1.157 +  // not explicitly) read-only.
   1.158 +
   1.159 +  int pkgInfoLen = *(intptr_t*)buffer;
   1.160 +  buffer += sizeof(intptr_t);
   1.161 +  number_of_entries = *(intptr_t*)buffer;
   1.162 +  buffer += sizeof(intptr_t);
   1.163 +  ClassLoader::create_package_info_table((HashtableBucket*)buffer, pkgInfoLen,
   1.164 +                                         number_of_entries);
   1.165 +  buffer += pkgInfoLen;
   1.166 +  ClassLoader::verify();
   1.167 +
   1.168 +  // The following data in the shared misc data region are the linked
   1.169 +  // list elements (HashtableEntry objects) for the symbol table, string
   1.170 +  // table, and shared dictionary.  The heap objects refered to by the
   1.171 +  // symbol table, string table, and shared dictionary are permanent and
   1.172 +  // unmovable.  Since new entries added to the string and symbol tables
   1.173 +  // are always added at the beginning of the linked lists, THESE LINKED
   1.174 +  // LIST ELEMENTS ARE READ-ONLY.
   1.175 +
   1.176 +  int len = *(intptr_t*)buffer; // skip over symbol table entries
   1.177 +  buffer += sizeof(intptr_t);
   1.178 +  buffer += len;
   1.179 +
   1.180 +  len = *(intptr_t*)buffer;     // skip over string table entries
   1.181 +  buffer += sizeof(intptr_t);
   1.182 +  buffer += len;
   1.183 +
   1.184 +  len = *(intptr_t*)buffer;     // skip over shared dictionary entries
   1.185 +  buffer += sizeof(intptr_t);
   1.186 +  buffer += len;
   1.187 +
   1.188 +  len = *(intptr_t*)buffer;     // skip over package info table entries
   1.189 +  buffer += sizeof(intptr_t);
   1.190 +  buffer += len;
   1.191 +
   1.192 +  len = *(intptr_t*)buffer;     // skip over package info table char[] arrays.
   1.193 +  buffer += sizeof(intptr_t);
   1.194 +  buffer += len;
   1.195 +
   1.196 +  oop* oop_array = (oop*)buffer;
   1.197 +  ReadClosure rc(&oop_array);
   1.198 +  serialize_oops(&rc);
   1.199 +}

mercurial