Wed, 06 Jan 2010 22:21:39 -0800
Merge
duke@435 | 1 | /* |
xdono@1014 | 2 | * Copyright 1998-2009 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/_cpCacheKlass.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | |
duke@435 | 29 | int constantPoolCacheKlass::oop_size(oop obj) const { |
duke@435 | 30 | assert(obj->is_constantPoolCache(), "must be constantPool"); |
duke@435 | 31 | return constantPoolCacheOop(obj)->object_size(); |
duke@435 | 32 | } |
duke@435 | 33 | |
duke@435 | 34 | |
jmasa@977 | 35 | constantPoolCacheOop constantPoolCacheKlass::allocate(int length, |
jmasa@977 | 36 | bool is_conc_safe, |
jmasa@977 | 37 | TRAPS) { |
duke@435 | 38 | // allocate memory |
duke@435 | 39 | int size = constantPoolCacheOopDesc::object_size(length); |
jmasa@977 | 40 | |
duke@435 | 41 | KlassHandle klass (THREAD, as_klassOop()); |
jmasa@977 | 42 | |
jmasa@977 | 43 | // This is the original code. The code from permanent_obj_allocate() |
jmasa@977 | 44 | // was in-lined to allow the setting of is_conc_safe before the klass |
jmasa@977 | 45 | // is installed. |
jmasa@977 | 46 | // constantPoolCacheOop cache = (constantPoolCacheOop) |
jmasa@977 | 47 | // CollectedHeap::permanent_obj_allocate(klass, size, CHECK_NULL); |
jmasa@977 | 48 | |
jmasa@977 | 49 | oop obj = CollectedHeap::permanent_obj_allocate_no_klass_install(klass, size, CHECK_NULL); |
jmasa@977 | 50 | constantPoolCacheOop cache = (constantPoolCacheOop) obj; |
jmasa@977 | 51 | cache->set_is_conc_safe(is_conc_safe); |
jmasa@977 | 52 | // The store to is_conc_safe must be visible before the klass |
jmasa@977 | 53 | // is set. This should be done safely because _is_conc_safe has |
jmasa@977 | 54 | // been declared volatile. If there are any problems, consider adding |
jmasa@977 | 55 | // OrderAccess::storestore(); |
jmasa@977 | 56 | CollectedHeap::post_allocation_install_obj_klass(klass, obj, size); |
jmasa@977 | 57 | NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value((HeapWord*) obj, |
jmasa@977 | 58 | size)); |
jmasa@977 | 59 | |
jmasa@977 | 60 | // The length field affects the size of the object. The allocation |
jmasa@977 | 61 | // above allocates the correct size (see calculation of "size") but |
jmasa@977 | 62 | // the size() method of the constant pool cache oop will not reflect |
jmasa@977 | 63 | // that size until the correct length is set. |
coleenp@548 | 64 | cache->set_length(length); |
jmasa@977 | 65 | |
jmasa@977 | 66 | // The store of the length must be visible before is_conc_safe is |
jmasa@977 | 67 | // set to a safe state. |
jmasa@977 | 68 | // This should be done safely because _is_conc_safe has |
jmasa@977 | 69 | // been declared volatile. If there are any problems, consider adding |
jmasa@977 | 70 | // OrderAccess::storestore(); |
jmasa@977 | 71 | cache->set_is_conc_safe(methodOopDesc::IsSafeConc); |
duke@435 | 72 | cache->set_constant_pool(NULL); |
duke@435 | 73 | return cache; |
duke@435 | 74 | } |
duke@435 | 75 | |
duke@435 | 76 | klassOop constantPoolCacheKlass::create_klass(TRAPS) { |
duke@435 | 77 | constantPoolCacheKlass o; |
coleenp@548 | 78 | KlassHandle h_this_klass(THREAD, Universe::klassKlassObj()); |
coleenp@548 | 79 | KlassHandle k = base_create_klass(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL); |
coleenp@548 | 80 | // Make sure size calculation is right |
coleenp@548 | 81 | assert(k()->size() == align_object_size(header_size()), "wrong size for object"); |
coleenp@548 | 82 | java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror |
duke@435 | 83 | return k(); |
duke@435 | 84 | } |
duke@435 | 85 | |
duke@435 | 86 | |
duke@435 | 87 | void constantPoolCacheKlass::oop_follow_contents(oop obj) { |
duke@435 | 88 | assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); |
duke@435 | 89 | constantPoolCacheOop cache = (constantPoolCacheOop)obj; |
duke@435 | 90 | // Performance tweak: We skip iterating over the klass pointer since we |
duke@435 | 91 | // know that Universe::constantPoolCacheKlassObj never moves. |
duke@435 | 92 | // gc of constant pool cache instance variables |
duke@435 | 93 | MarkSweep::mark_and_push((oop*)cache->constant_pool_addr()); |
duke@435 | 94 | // gc of constant pool cache entries |
duke@435 | 95 | int i = cache->length(); |
duke@435 | 96 | while (i-- > 0) cache->entry_at(i)->follow_contents(); |
duke@435 | 97 | } |
duke@435 | 98 | |
duke@435 | 99 | #ifndef SERIALGC |
duke@435 | 100 | void constantPoolCacheKlass::oop_follow_contents(ParCompactionManager* cm, |
duke@435 | 101 | oop obj) { |
duke@435 | 102 | assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); |
duke@435 | 103 | constantPoolCacheOop cache = (constantPoolCacheOop)obj; |
duke@435 | 104 | // Performance tweak: We skip iterating over the klass pointer since we |
duke@435 | 105 | // know that Universe::constantPoolCacheKlassObj never moves. |
duke@435 | 106 | // gc of constant pool cache instance variables |
duke@435 | 107 | PSParallelCompact::mark_and_push(cm, (oop*)cache->constant_pool_addr()); |
duke@435 | 108 | // gc of constant pool cache entries |
duke@435 | 109 | int i = cache->length(); |
duke@435 | 110 | while (i-- > 0) cache->entry_at(i)->follow_contents(cm); |
duke@435 | 111 | } |
duke@435 | 112 | #endif // SERIALGC |
duke@435 | 113 | |
duke@435 | 114 | |
duke@435 | 115 | int constantPoolCacheKlass::oop_oop_iterate(oop obj, OopClosure* blk) { |
duke@435 | 116 | assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); |
duke@435 | 117 | constantPoolCacheOop cache = (constantPoolCacheOop)obj; |
duke@435 | 118 | // Get size before changing pointers. |
duke@435 | 119 | // Don't call size() or oop_size() since that is a virtual call. |
duke@435 | 120 | int size = cache->object_size(); |
duke@435 | 121 | // Performance tweak: We skip iterating over the klass pointer since we |
duke@435 | 122 | // know that Universe::constantPoolCacheKlassObj never moves. |
duke@435 | 123 | // iteration over constant pool cache instance variables |
duke@435 | 124 | blk->do_oop((oop*)cache->constant_pool_addr()); |
duke@435 | 125 | // iteration over constant pool cache entries |
duke@435 | 126 | for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->oop_iterate(blk); |
duke@435 | 127 | return size; |
duke@435 | 128 | } |
duke@435 | 129 | |
duke@435 | 130 | |
duke@435 | 131 | int constantPoolCacheKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) { |
duke@435 | 132 | assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); |
duke@435 | 133 | constantPoolCacheOop cache = (constantPoolCacheOop)obj; |
duke@435 | 134 | // Get size before changing pointers. |
duke@435 | 135 | // Don't call size() or oop_size() since that is a virtual call. |
duke@435 | 136 | int size = cache->object_size(); |
duke@435 | 137 | // Performance tweak: We skip iterating over the klass pointer since we |
duke@435 | 138 | // know that Universe::constantPoolCacheKlassObj never moves. |
duke@435 | 139 | // iteration over constant pool cache instance variables |
duke@435 | 140 | oop* addr = (oop*)cache->constant_pool_addr(); |
duke@435 | 141 | if (mr.contains(addr)) blk->do_oop(addr); |
duke@435 | 142 | // iteration over constant pool cache entries |
duke@435 | 143 | for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->oop_iterate_m(blk, mr); |
duke@435 | 144 | return size; |
duke@435 | 145 | } |
duke@435 | 146 | |
duke@435 | 147 | int constantPoolCacheKlass::oop_adjust_pointers(oop obj) { |
duke@435 | 148 | assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); |
duke@435 | 149 | constantPoolCacheOop cache = (constantPoolCacheOop)obj; |
duke@435 | 150 | // Get size before changing pointers. |
duke@435 | 151 | // Don't call size() or oop_size() since that is a virtual call. |
duke@435 | 152 | int size = cache->object_size(); |
duke@435 | 153 | // Performance tweak: We skip iterating over the klass pointer since we |
duke@435 | 154 | // know that Universe::constantPoolCacheKlassObj never moves. |
duke@435 | 155 | // Iteration over constant pool cache instance variables |
duke@435 | 156 | MarkSweep::adjust_pointer((oop*)cache->constant_pool_addr()); |
duke@435 | 157 | // iteration over constant pool cache entries |
duke@435 | 158 | for (int i = 0; i < cache->length(); i++) |
duke@435 | 159 | cache->entry_at(i)->adjust_pointers(); |
duke@435 | 160 | return size; |
duke@435 | 161 | } |
duke@435 | 162 | |
jmasa@977 | 163 | bool constantPoolCacheKlass::oop_is_conc_safe(oop obj) const { |
jmasa@981 | 164 | assert(obj->is_constantPoolCache(), "should be constant pool"); |
jmasa@977 | 165 | return constantPoolCacheOop(obj)->is_conc_safe(); |
jmasa@977 | 166 | } |
jmasa@977 | 167 | |
duke@435 | 168 | #ifndef SERIALGC |
duke@435 | 169 | void constantPoolCacheKlass::oop_copy_contents(PSPromotionManager* pm, |
duke@435 | 170 | oop obj) { |
duke@435 | 171 | assert(obj->is_constantPoolCache(), "should be constant pool"); |
jrose@1161 | 172 | if (EnableInvokeDynamic) { |
jrose@1161 | 173 | constantPoolCacheOop cache = (constantPoolCacheOop)obj; |
jrose@1161 | 174 | // during a scavenge, it is safe to inspect my pool, since it is perm |
jrose@1161 | 175 | constantPoolOop pool = cache->constant_pool(); |
jrose@1161 | 176 | assert(pool->is_constantPool(), "should be constant pool"); |
jrose@1161 | 177 | if (pool->has_invokedynamic()) { |
jrose@1161 | 178 | for (int i = 0; i < cache->length(); i++) { |
jrose@1161 | 179 | ConstantPoolCacheEntry* e = cache->entry_at(i); |
jrose@1161 | 180 | oop* p = (oop*)&e->_f1; |
jrose@1161 | 181 | if (e->is_secondary_entry()) { |
jrose@1161 | 182 | if (PSScavenge::should_scavenge(p)) |
jrose@1161 | 183 | pm->claim_or_forward_breadth(p); |
jrose@1161 | 184 | assert(!(e->is_vfinal() && PSScavenge::should_scavenge((oop*)&e->_f2)), |
jrose@1161 | 185 | "no live oops here"); |
jrose@1161 | 186 | } |
jrose@1161 | 187 | } |
jrose@1161 | 188 | } |
jrose@1161 | 189 | } |
duke@435 | 190 | } |
duke@435 | 191 | |
duke@435 | 192 | void constantPoolCacheKlass::oop_push_contents(PSPromotionManager* pm, |
duke@435 | 193 | oop obj) { |
duke@435 | 194 | assert(obj->is_constantPoolCache(), "should be constant pool"); |
jrose@1161 | 195 | if (EnableInvokeDynamic) { |
jrose@1161 | 196 | constantPoolCacheOop cache = (constantPoolCacheOop)obj; |
jrose@1161 | 197 | // during a scavenge, it is safe to inspect my pool, since it is perm |
jrose@1161 | 198 | constantPoolOop pool = cache->constant_pool(); |
jrose@1161 | 199 | assert(pool->is_constantPool(), "should be constant pool"); |
jrose@1161 | 200 | if (pool->has_invokedynamic()) { |
jrose@1161 | 201 | for (int i = 0; i < cache->length(); i++) { |
jrose@1161 | 202 | ConstantPoolCacheEntry* e = cache->entry_at(i); |
jrose@1161 | 203 | oop* p = (oop*)&e->_f1; |
jrose@1161 | 204 | if (e->is_secondary_entry()) { |
jrose@1161 | 205 | if (PSScavenge::should_scavenge(p)) |
jrose@1161 | 206 | pm->claim_or_forward_depth(p); |
jrose@1161 | 207 | assert(!(e->is_vfinal() && PSScavenge::should_scavenge((oop*)&e->_f2)), |
jrose@1161 | 208 | "no live oops here"); |
jrose@1161 | 209 | } |
jrose@1161 | 210 | } |
jrose@1161 | 211 | } |
jrose@1161 | 212 | } |
duke@435 | 213 | } |
duke@435 | 214 | |
duke@435 | 215 | int |
duke@435 | 216 | constantPoolCacheKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { |
duke@435 | 217 | assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); |
duke@435 | 218 | constantPoolCacheOop cache = (constantPoolCacheOop)obj; |
duke@435 | 219 | |
duke@435 | 220 | // Iteration over constant pool cache instance variables |
duke@435 | 221 | PSParallelCompact::adjust_pointer((oop*)cache->constant_pool_addr()); |
duke@435 | 222 | |
duke@435 | 223 | // iteration over constant pool cache entries |
duke@435 | 224 | for (int i = 0; i < cache->length(); ++i) { |
duke@435 | 225 | cache->entry_at(i)->update_pointers(); |
duke@435 | 226 | } |
duke@435 | 227 | |
duke@435 | 228 | return cache->object_size(); |
duke@435 | 229 | } |
duke@435 | 230 | |
duke@435 | 231 | int |
duke@435 | 232 | constantPoolCacheKlass::oop_update_pointers(ParCompactionManager* cm, oop obj, |
duke@435 | 233 | HeapWord* beg_addr, |
duke@435 | 234 | HeapWord* end_addr) { |
duke@435 | 235 | assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); |
duke@435 | 236 | constantPoolCacheOop cache = (constantPoolCacheOop)obj; |
duke@435 | 237 | |
duke@435 | 238 | // Iteration over constant pool cache instance variables |
duke@435 | 239 | oop* p; |
duke@435 | 240 | p = (oop*)cache->constant_pool_addr(); |
duke@435 | 241 | PSParallelCompact::adjust_pointer(p, beg_addr, end_addr); |
duke@435 | 242 | |
duke@435 | 243 | // Iteration over constant pool cache entries |
duke@435 | 244 | for (int i = 0; i < cache->length(); ++i) { |
duke@435 | 245 | cache->entry_at(i)->update_pointers(beg_addr, end_addr); |
duke@435 | 246 | } |
duke@435 | 247 | return cache->object_size(); |
duke@435 | 248 | } |
duke@435 | 249 | #endif // SERIALGC |
duke@435 | 250 | |
duke@435 | 251 | #ifndef PRODUCT |
duke@435 | 252 | |
duke@435 | 253 | void constantPoolCacheKlass::oop_print_on(oop obj, outputStream* st) { |
duke@435 | 254 | assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); |
duke@435 | 255 | constantPoolCacheOop cache = (constantPoolCacheOop)obj; |
duke@435 | 256 | // super print |
coleenp@548 | 257 | Klass::oop_print_on(obj, st); |
duke@435 | 258 | // print constant pool cache entries |
duke@435 | 259 | for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->print(st, i); |
duke@435 | 260 | } |
duke@435 | 261 | |
duke@435 | 262 | #endif |
duke@435 | 263 | |
duke@435 | 264 | void constantPoolCacheKlass::oop_verify_on(oop obj, outputStream* st) { |
duke@435 | 265 | guarantee(obj->is_constantPoolCache(), "obj must be constant pool cache"); |
duke@435 | 266 | constantPoolCacheOop cache = (constantPoolCacheOop)obj; |
duke@435 | 267 | // super verify |
coleenp@548 | 268 | Klass::oop_verify_on(obj, st); |
duke@435 | 269 | // print constant pool cache entries |
duke@435 | 270 | for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->verify(st); |
duke@435 | 271 | } |
duke@435 | 272 | |
duke@435 | 273 | |
duke@435 | 274 | const char* constantPoolCacheKlass::internal_name() const { |
duke@435 | 275 | return "{constant pool cache}"; |
duke@435 | 276 | } |