Mon, 09 Jun 2008 11:51:19 -0400
6687581: Make CMS work with compressed oops
Summary: Make FreeChunk read markword instead of LSB in _klass pointer to indicate that it's a FreeChunk for compressed oops.
Reviewed-by: ysr, jmasa
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 2003-2006 Sun Microsystems, Inc. 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 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_constMethodKlass.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | |
duke@435 | 29 | klassOop constMethodKlass::create_klass(TRAPS) { |
duke@435 | 30 | constMethodKlass o; |
duke@435 | 31 | KlassHandle h_this_klass(THREAD, Universe::klassKlassObj()); |
duke@435 | 32 | KlassHandle k = base_create_klass(h_this_klass, header_size(), |
duke@435 | 33 | o.vtbl_value(), CHECK_NULL); |
duke@435 | 34 | // Make sure size calculation is right |
duke@435 | 35 | assert(k()->size() == align_object_size(header_size()), |
duke@435 | 36 | "wrong size for object"); |
duke@435 | 37 | //java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror |
duke@435 | 38 | return k(); |
duke@435 | 39 | } |
duke@435 | 40 | |
duke@435 | 41 | |
duke@435 | 42 | int constMethodKlass::oop_size(oop obj) const { |
duke@435 | 43 | assert(obj->is_constMethod(), "must be constMethod oop"); |
duke@435 | 44 | return constMethodOop(obj)->object_size(); |
duke@435 | 45 | } |
duke@435 | 46 | |
duke@435 | 47 | bool constMethodKlass::oop_is_parsable(oop obj) const { |
duke@435 | 48 | assert(obj->is_constMethod(), "must be constMethod oop"); |
duke@435 | 49 | return constMethodOop(obj)->object_is_parsable(); |
duke@435 | 50 | } |
duke@435 | 51 | |
duke@435 | 52 | constMethodOop constMethodKlass::allocate(int byte_code_size, |
duke@435 | 53 | int compressed_line_number_size, |
duke@435 | 54 | int localvariable_table_length, |
duke@435 | 55 | int checked_exceptions_length, |
duke@435 | 56 | TRAPS) { |
duke@435 | 57 | |
duke@435 | 58 | int size = constMethodOopDesc::object_size(byte_code_size, |
duke@435 | 59 | compressed_line_number_size, |
duke@435 | 60 | localvariable_table_length, |
duke@435 | 61 | checked_exceptions_length); |
duke@435 | 62 | KlassHandle h_k(THREAD, as_klassOop()); |
duke@435 | 63 | constMethodOop cm = (constMethodOop) |
duke@435 | 64 | CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL); |
duke@435 | 65 | assert(!cm->is_parsable(), "Not yet safely parsable"); |
duke@435 | 66 | No_Safepoint_Verifier no_safepoint; |
duke@435 | 67 | cm->set_interpreter_kind(Interpreter::invalid); |
duke@435 | 68 | cm->init_fingerprint(); |
duke@435 | 69 | cm->set_method(NULL); |
duke@435 | 70 | cm->set_stackmap_data(NULL); |
duke@435 | 71 | cm->set_exception_table(NULL); |
duke@435 | 72 | cm->set_code_size(byte_code_size); |
duke@435 | 73 | cm->set_constMethod_size(size); |
duke@435 | 74 | cm->set_inlined_tables_length(checked_exceptions_length, |
duke@435 | 75 | compressed_line_number_size, |
duke@435 | 76 | localvariable_table_length); |
duke@435 | 77 | assert(cm->size() == size, "wrong size for object"); |
duke@435 | 78 | cm->set_partially_loaded(); |
duke@435 | 79 | assert(cm->is_parsable(), "Is safely parsable by gc"); |
duke@435 | 80 | return cm; |
duke@435 | 81 | } |
duke@435 | 82 | |
duke@435 | 83 | void constMethodKlass::oop_follow_contents(oop obj) { |
duke@435 | 84 | assert (obj->is_constMethod(), "object must be constMethod"); |
duke@435 | 85 | constMethodOop cm = constMethodOop(obj); |
duke@435 | 86 | MarkSweep::mark_and_push(cm->adr_method()); |
duke@435 | 87 | MarkSweep::mark_and_push(cm->adr_stackmap_data()); |
duke@435 | 88 | MarkSweep::mark_and_push(cm->adr_exception_table()); |
duke@435 | 89 | // Performance tweak: We skip iterating over the klass pointer since we |
duke@435 | 90 | // know that Universe::constMethodKlassObj never moves. |
duke@435 | 91 | } |
duke@435 | 92 | |
duke@435 | 93 | #ifndef SERIALGC |
duke@435 | 94 | void constMethodKlass::oop_follow_contents(ParCompactionManager* cm, |
duke@435 | 95 | oop obj) { |
duke@435 | 96 | assert (obj->is_constMethod(), "object must be constMethod"); |
duke@435 | 97 | constMethodOop cm_oop = constMethodOop(obj); |
duke@435 | 98 | PSParallelCompact::mark_and_push(cm, cm_oop->adr_method()); |
duke@435 | 99 | PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data()); |
duke@435 | 100 | PSParallelCompact::mark_and_push(cm, cm_oop->adr_exception_table()); |
duke@435 | 101 | // Performance tweak: We skip iterating over the klass pointer since we |
duke@435 | 102 | // know that Universe::constMethodKlassObj never moves. |
duke@435 | 103 | } |
duke@435 | 104 | #endif // SERIALGC |
duke@435 | 105 | |
duke@435 | 106 | int constMethodKlass::oop_oop_iterate(oop obj, OopClosure* blk) { |
duke@435 | 107 | assert (obj->is_constMethod(), "object must be constMethod"); |
duke@435 | 108 | constMethodOop cm = constMethodOop(obj); |
duke@435 | 109 | blk->do_oop(cm->adr_method()); |
duke@435 | 110 | blk->do_oop(cm->adr_stackmap_data()); |
duke@435 | 111 | blk->do_oop(cm->adr_exception_table()); |
duke@435 | 112 | // Get size before changing pointers. |
duke@435 | 113 | // Don't call size() or oop_size() since that is a virtual call. |
duke@435 | 114 | int size = cm->object_size(); |
duke@435 | 115 | return size; |
duke@435 | 116 | } |
duke@435 | 117 | |
duke@435 | 118 | |
duke@435 | 119 | int constMethodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) { |
duke@435 | 120 | assert (obj->is_constMethod(), "object must be constMethod"); |
duke@435 | 121 | constMethodOop cm = constMethodOop(obj); |
duke@435 | 122 | oop* adr; |
duke@435 | 123 | adr = cm->adr_method(); |
duke@435 | 124 | if (mr.contains(adr)) blk->do_oop(adr); |
duke@435 | 125 | adr = cm->adr_stackmap_data(); |
duke@435 | 126 | if (mr.contains(adr)) blk->do_oop(adr); |
duke@435 | 127 | adr = cm->adr_exception_table(); |
duke@435 | 128 | if (mr.contains(adr)) blk->do_oop(adr); |
duke@435 | 129 | // Get size before changing pointers. |
duke@435 | 130 | // Don't call size() or oop_size() since that is a virtual call. |
duke@435 | 131 | int size = cm->object_size(); |
duke@435 | 132 | // Performance tweak: We skip iterating over the klass pointer since we |
duke@435 | 133 | // know that Universe::constMethodKlassObj never moves. |
duke@435 | 134 | return size; |
duke@435 | 135 | } |
duke@435 | 136 | |
duke@435 | 137 | |
duke@435 | 138 | int constMethodKlass::oop_adjust_pointers(oop obj) { |
duke@435 | 139 | assert(obj->is_constMethod(), "should be constMethod"); |
duke@435 | 140 | constMethodOop cm = constMethodOop(obj); |
duke@435 | 141 | MarkSweep::adjust_pointer(cm->adr_method()); |
duke@435 | 142 | MarkSweep::adjust_pointer(cm->adr_stackmap_data()); |
duke@435 | 143 | MarkSweep::adjust_pointer(cm->adr_exception_table()); |
duke@435 | 144 | // Get size before changing pointers. |
duke@435 | 145 | // Don't call size() or oop_size() since that is a virtual call. |
duke@435 | 146 | int size = cm->object_size(); |
duke@435 | 147 | // Performance tweak: We skip iterating over the klass pointer since we |
duke@435 | 148 | // know that Universe::constMethodKlassObj never moves. |
duke@435 | 149 | return size; |
duke@435 | 150 | } |
duke@435 | 151 | |
duke@435 | 152 | #ifndef SERIALGC |
duke@435 | 153 | void constMethodKlass::oop_copy_contents(PSPromotionManager* pm, oop obj) { |
duke@435 | 154 | assert(obj->is_constMethod(), "should be constMethod"); |
duke@435 | 155 | } |
duke@435 | 156 | |
duke@435 | 157 | void constMethodKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { |
duke@435 | 158 | assert(obj->is_constMethod(), "should be constMethod"); |
duke@435 | 159 | } |
duke@435 | 160 | |
duke@435 | 161 | int constMethodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { |
duke@435 | 162 | assert(obj->is_constMethod(), "should be constMethod"); |
duke@435 | 163 | constMethodOop cm_oop = constMethodOop(obj); |
duke@435 | 164 | #if 0 |
duke@435 | 165 | PSParallelCompact::adjust_pointer(cm_oop->adr_method()); |
duke@435 | 166 | PSParallelCompact::adjust_pointer(cm_oop->adr_exception_table()); |
duke@435 | 167 | PSParallelCompact::adjust_pointer(cm_oop->adr_stackmap_data()); |
duke@435 | 168 | #endif |
duke@435 | 169 | oop* const beg_oop = cm_oop->oop_block_beg(); |
duke@435 | 170 | oop* const end_oop = cm_oop->oop_block_end(); |
duke@435 | 171 | for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) { |
duke@435 | 172 | PSParallelCompact::adjust_pointer(cur_oop); |
duke@435 | 173 | } |
duke@435 | 174 | return cm_oop->object_size(); |
duke@435 | 175 | } |
duke@435 | 176 | |
duke@435 | 177 | int constMethodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj, |
duke@435 | 178 | HeapWord* beg_addr, |
duke@435 | 179 | HeapWord* end_addr) { |
duke@435 | 180 | assert(obj->is_constMethod(), "should be constMethod"); |
duke@435 | 181 | constMethodOop cm_oop = constMethodOop(obj); |
duke@435 | 182 | |
duke@435 | 183 | oop* const beg_oop = MAX2((oop*)beg_addr, cm_oop->oop_block_beg()); |
duke@435 | 184 | oop* const end_oop = MIN2((oop*)end_addr, cm_oop->oop_block_end()); |
duke@435 | 185 | for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) { |
duke@435 | 186 | PSParallelCompact::adjust_pointer(cur_oop); |
duke@435 | 187 | } |
duke@435 | 188 | |
duke@435 | 189 | return cm_oop->object_size(); |
duke@435 | 190 | } |
duke@435 | 191 | #endif // SERIALGC |
duke@435 | 192 | |
duke@435 | 193 | #ifndef PRODUCT |
duke@435 | 194 | |
duke@435 | 195 | // Printing |
duke@435 | 196 | |
duke@435 | 197 | void constMethodKlass::oop_print_on(oop obj, outputStream* st) { |
duke@435 | 198 | ResourceMark rm; |
duke@435 | 199 | assert(obj->is_constMethod(), "must be constMethod"); |
duke@435 | 200 | Klass::oop_print_on(obj, st); |
duke@435 | 201 | constMethodOop m = constMethodOop(obj); |
duke@435 | 202 | st->print(" - method: " INTPTR_FORMAT " ", (address)m->method()); |
duke@435 | 203 | m->method()->print_value_on(st); st->cr(); |
duke@435 | 204 | st->print(" - exceptions: " INTPTR_FORMAT "\n", (address)m->exception_table()); |
duke@435 | 205 | if (m->has_stackmap_table()) { |
duke@435 | 206 | st->print(" - stackmap data: "); |
duke@435 | 207 | m->stackmap_data()->print_value_on(st); |
duke@435 | 208 | st->cr(); |
duke@435 | 209 | } |
duke@435 | 210 | } |
duke@435 | 211 | |
duke@435 | 212 | |
duke@435 | 213 | // Short version of printing constMethodOop - just print the name of the |
duke@435 | 214 | // method it belongs to. |
duke@435 | 215 | void constMethodKlass::oop_print_value_on(oop obj, outputStream* st) { |
duke@435 | 216 | assert(obj->is_constMethod(), "must be constMethod"); |
duke@435 | 217 | constMethodOop m = constMethodOop(obj); |
duke@435 | 218 | st->print(" const part of method " ); |
duke@435 | 219 | m->method()->print_value_on(st); |
duke@435 | 220 | } |
duke@435 | 221 | |
duke@435 | 222 | #endif // PRODUCT |
duke@435 | 223 | |
duke@435 | 224 | const char* constMethodKlass::internal_name() const { |
duke@435 | 225 | return "{constMethod}"; |
duke@435 | 226 | } |
duke@435 | 227 | |
duke@435 | 228 | |
duke@435 | 229 | // Verification |
duke@435 | 230 | |
duke@435 | 231 | void constMethodKlass::oop_verify_on(oop obj, outputStream* st) { |
duke@435 | 232 | Klass::oop_verify_on(obj, st); |
duke@435 | 233 | guarantee(obj->is_constMethod(), "object must be constMethod"); |
duke@435 | 234 | constMethodOop m = constMethodOop(obj); |
duke@435 | 235 | guarantee(m->is_perm(), "should be in permspace"); |
duke@435 | 236 | |
duke@435 | 237 | // Verification can occur during oop construction before the method or |
duke@435 | 238 | // other fields have been initialized. |
duke@435 | 239 | if (!obj->partially_loaded()) { |
duke@435 | 240 | guarantee(m->method()->is_perm(), "should be in permspace"); |
duke@435 | 241 | guarantee(m->method()->is_method(), "should be method"); |
duke@435 | 242 | typeArrayOop stackmap_data = m->stackmap_data(); |
duke@435 | 243 | guarantee(stackmap_data == NULL || |
duke@435 | 244 | stackmap_data->is_perm(), "should be in permspace"); |
duke@435 | 245 | guarantee(m->exception_table()->is_perm(), "should be in permspace"); |
duke@435 | 246 | guarantee(m->exception_table()->is_typeArray(), "should be type array"); |
duke@435 | 247 | |
duke@435 | 248 | address m_end = (address)((oop*) m + m->size()); |
duke@435 | 249 | address compressed_table_start = m->code_end(); |
duke@435 | 250 | guarantee(compressed_table_start <= m_end, "invalid method layout"); |
duke@435 | 251 | address compressed_table_end = compressed_table_start; |
duke@435 | 252 | // Verify line number table |
duke@435 | 253 | if (m->has_linenumber_table()) { |
duke@435 | 254 | CompressedLineNumberReadStream stream(m->compressed_linenumber_table()); |
duke@435 | 255 | while (stream.read_pair()) { |
duke@435 | 256 | guarantee(stream.bci() >= 0 && stream.bci() <= m->code_size(), "invalid bci in line number table"); |
duke@435 | 257 | } |
duke@435 | 258 | compressed_table_end += stream.position(); |
duke@435 | 259 | } |
duke@435 | 260 | guarantee(compressed_table_end <= m_end, "invalid method layout"); |
duke@435 | 261 | // Verify checked exceptions and local variable tables |
duke@435 | 262 | if (m->has_checked_exceptions()) { |
duke@435 | 263 | u2* addr = m->checked_exceptions_length_addr(); |
duke@435 | 264 | guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout"); |
duke@435 | 265 | } |
duke@435 | 266 | if (m->has_localvariable_table()) { |
duke@435 | 267 | u2* addr = m->localvariable_table_length_addr(); |
duke@435 | 268 | guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout"); |
duke@435 | 269 | } |
duke@435 | 270 | // Check compressed_table_end relative to uncompressed_table_start |
duke@435 | 271 | u2* uncompressed_table_start; |
duke@435 | 272 | if (m->has_localvariable_table()) { |
duke@435 | 273 | uncompressed_table_start = (u2*) m->localvariable_table_start(); |
duke@435 | 274 | } else { |
duke@435 | 275 | if (m->has_checked_exceptions()) { |
duke@435 | 276 | uncompressed_table_start = (u2*) m->checked_exceptions_start(); |
duke@435 | 277 | } else { |
duke@435 | 278 | uncompressed_table_start = (u2*) m_end; |
duke@435 | 279 | } |
duke@435 | 280 | } |
duke@435 | 281 | int gap = (intptr_t) uncompressed_table_start - (intptr_t) compressed_table_end; |
duke@435 | 282 | int max_gap = align_object_size(1)*BytesPerWord; |
duke@435 | 283 | guarantee(gap >= 0 && gap < max_gap, "invalid method layout"); |
duke@435 | 284 | } |
duke@435 | 285 | } |
duke@435 | 286 | |
duke@435 | 287 | bool constMethodKlass::oop_partially_loaded(oop obj) const { |
duke@435 | 288 | assert(obj->is_constMethod(), "object must be klass"); |
duke@435 | 289 | constMethodOop m = constMethodOop(obj); |
duke@435 | 290 | // check whether exception_table points to self (flag for partially loaded) |
duke@435 | 291 | return m->exception_table() == (typeArrayOop)obj; |
duke@435 | 292 | } |
duke@435 | 293 | |
duke@435 | 294 | |
duke@435 | 295 | // The exception_table is the last field set when loading an object. |
duke@435 | 296 | void constMethodKlass::oop_set_partially_loaded(oop obj) { |
duke@435 | 297 | assert(obj->is_constMethod(), "object must be klass"); |
duke@435 | 298 | constMethodOop m = constMethodOop(obj); |
duke@435 | 299 | // Temporarily set exception_table to point to self |
duke@435 | 300 | m->set_exception_table((typeArrayOop)obj); |
duke@435 | 301 | } |