src/share/vm/memory/restore.cpp

Fri, 15 Apr 2011 09:36:28 -0400

author
coleenp
date
Fri, 15 Apr 2011 09:36:28 -0400
changeset 2777
8ce625481709
parent 2708
1d1603768966
child 3900
d2a62e0f25eb
permissions
-rw-r--r--

7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
Summary: Make CDS reorder vtables so that dump time vtables match run time order, so when redefine classes reinitializes them, they aren't in the wrong order.
Reviewed-by: dcubed, acorn

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

mercurial