src/share/vm/memory/restore.cpp

Thu, 24 Mar 2011 15:47:01 -0700

author
ysr
date
Thu, 24 Mar 2011 15:47:01 -0700
changeset 2710
5134fa1cfe63
parent 2497
3582bf76420e
child 2708
1d1603768966
permissions
-rw-r--r--

7029036: Card-table verification hangs with all framework collectors, except G1, even before the first GC
Summary: When verifying clean card ranges, use memory-range-bounded iteration over oops of objects overlapping that range, thus avoiding the otherwise quadratic worst-case cost of scanning large object arrays.
Reviewed-by: jmasa, jwilhelm, tonyp

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

mercurial