1 #ifdef USE_PRAGMA_IDENT_SRC 2 #pragma ident "@(#)cpCacheKlass.cpp 1.46 07/05/29 09:44:18 JVM" 3 #endif 4 /* 5 * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved. 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 * 8 * This code is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License version 2 only, as 10 * published by the Free Software Foundation. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 23 * CA 95054 USA or visit www.sun.com if you need additional information or 24 * have any questions. 25 * 26 */ 27 28 #include "incls/_precompiled.incl" 29 #include "incls/_cpCacheKlass.cpp.incl" 30 31 32 int constantPoolCacheKlass::oop_size(oop obj) const { 33 assert(obj->is_constantPoolCache(), "must be constantPool"); 34 return constantPoolCacheOop(obj)->object_size(); 35 } 36 37 38 constantPoolCacheOop constantPoolCacheKlass::allocate(int length, TRAPS) { 39 // allocate memory 40 int size = constantPoolCacheOopDesc::object_size(length); 41 KlassHandle klass (THREAD, as_klassOop()); 42 constantPoolCacheOop cache = (constantPoolCacheOop) 43 CollectedHeap::permanent_obj_allocate(klass, size, CHECK_NULL); 44 cache->set_length(length); 45 cache->set_constant_pool(NULL); 46 return cache; 47 } 48 49 klassOop constantPoolCacheKlass::create_klass(TRAPS) { 50 constantPoolCacheKlass o; 51 KlassHandle h_this_klass(THREAD, Universe::klassKlassObj()); 52 KlassHandle k = base_create_klass(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL); 53 // Make sure size calculation is right 54 assert(k()->size() == align_object_size(header_size()), "wrong size for object"); 55 java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror 56 return k(); 57 } 58 59 60 void constantPoolCacheKlass::oop_follow_contents(oop obj) { 61 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 62 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 63 // Performance tweak: We skip iterating over the klass pointer since we 64 // know that Universe::constantPoolCacheKlassObj never moves. 65 // gc of constant pool cache instance variables 66 MarkSweep::mark_and_push((oop*)cache->constant_pool_addr()); 67 // gc of constant pool cache entries 68 int i = cache->length(); 69 while (i-- > 0) cache->entry_at(i)->follow_contents(); 70 } 71 72 #ifndef SERIALGC 73 void constantPoolCacheKlass::oop_follow_contents(ParCompactionManager* cm, 74 oop obj) { 75 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 76 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 77 // Performance tweak: We skip iterating over the klass pointer since we 78 // know that Universe::constantPoolCacheKlassObj never moves. 79 // gc of constant pool cache instance variables 80 PSParallelCompact::mark_and_push(cm, (oop*)cache->constant_pool_addr()); 81 // gc of constant pool cache entries 82 int i = cache->length(); 83 while (i-- > 0) cache->entry_at(i)->follow_contents(cm); 84 } 85 #endif // SERIALGC 86 87 88 int constantPoolCacheKlass::oop_oop_iterate(oop obj, OopClosure* blk) { 89 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 90 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 91 // Get size before changing pointers. 92 // Don't call size() or oop_size() since that is a virtual call. 93 int size = cache->object_size(); 94 // Performance tweak: We skip iterating over the klass pointer since we 95 // know that Universe::constantPoolCacheKlassObj never moves. 96 // iteration over constant pool cache instance variables 97 blk->do_oop((oop*)cache->constant_pool_addr()); 98 // iteration over constant pool cache entries 99 for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->oop_iterate(blk); 100 return size; 101 } 102 103 104 int constantPoolCacheKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) { 105 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 106 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 107 // Get size before changing pointers. 108 // Don't call size() or oop_size() since that is a virtual call. 109 int size = cache->object_size(); 110 // Performance tweak: We skip iterating over the klass pointer since we 111 // know that Universe::constantPoolCacheKlassObj never moves. 112 // iteration over constant pool cache instance variables 113 oop* addr = (oop*)cache->constant_pool_addr(); 114 if (mr.contains(addr)) blk->do_oop(addr); 115 // iteration over constant pool cache entries 116 for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->oop_iterate_m(blk, mr); 117 return size; 118 } 119 120 121 int constantPoolCacheKlass::oop_adjust_pointers(oop obj) { 122 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 123 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 124 // Get size before changing pointers. 125 // Don't call size() or oop_size() since that is a virtual call. 126 int size = cache->object_size(); 127 // Performance tweak: We skip iterating over the klass pointer since we 128 // know that Universe::constantPoolCacheKlassObj never moves. 129 // Iteration over constant pool cache instance variables 130 MarkSweep::adjust_pointer((oop*)cache->constant_pool_addr()); 131 // iteration over constant pool cache entries 132 for (int i = 0; i < cache->length(); i++) 133 cache->entry_at(i)->adjust_pointers(); 134 return size; 135 } 136 137 #ifndef SERIALGC 138 void constantPoolCacheKlass::oop_copy_contents(PSPromotionManager* pm, 139 oop obj) { 140 assert(obj->is_constantPoolCache(), "should be constant pool"); 141 } 142 143 void constantPoolCacheKlass::oop_push_contents(PSPromotionManager* pm, 144 oop obj) { 145 assert(obj->is_constantPoolCache(), "should be constant pool"); 146 } 147 148 int 149 constantPoolCacheKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { 150 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 151 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 152 153 // Iteration over constant pool cache instance variables 154 PSParallelCompact::adjust_pointer((oop*)cache->constant_pool_addr()); 155 156 // iteration over constant pool cache entries 157 for (int i = 0; i < cache->length(); ++i) { 158 cache->entry_at(i)->update_pointers(); 159 } 160 161 return cache->object_size(); 162 } 163 164 int 165 constantPoolCacheKlass::oop_update_pointers(ParCompactionManager* cm, oop obj, 166 HeapWord* beg_addr, 167 HeapWord* end_addr) { 168 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 169 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 170 171 // Iteration over constant pool cache instance variables 172 oop* p; 173 p = (oop*)cache->constant_pool_addr(); 174 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr); 175 176 // Iteration over constant pool cache entries 177 for (int i = 0; i < cache->length(); ++i) { 178 cache->entry_at(i)->update_pointers(beg_addr, end_addr); 179 } 180 return cache->object_size(); 181 } 182 #endif // SERIALGC 183 184 #ifndef PRODUCT 185 186 void constantPoolCacheKlass::oop_print_on(oop obj, outputStream* st) { 187 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 188 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 189 // super print 190 Klass::oop_print_on(obj, st); 191 // print constant pool cache entries 192 for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->print(st, i); 193 } 194 195 #endif 196 197 void constantPoolCacheKlass::oop_verify_on(oop obj, outputStream* st) { 198 guarantee(obj->is_constantPoolCache(), "obj must be constant pool cache"); 199 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 200 // super verify 201 Klass::oop_verify_on(obj, st); 202 // print constant pool cache entries 203 for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->verify(st); 204 } 205 206 207 const char* constantPoolCacheKlass::internal_name() const { 208 return "{constant pool cache}"; 209 } 210