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-2006 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_array_allocate(klass, size, length, CHECK_NULL); 44 cache->set_constant_pool(NULL); 45 return cache; 46 } 47 48 49 klassOop constantPoolCacheKlass::create_klass(TRAPS) { 50 constantPoolCacheKlass o; 51 KlassHandle klassklass(THREAD, Universe::arrayKlassKlassObj()); 52 arrayKlassHandle k = base_create_array_klass(o.vtbl_value(), header_size(), klassklass, CHECK_NULL); 53 KlassHandle super (THREAD, k->super()); 54 complete_create_array_klass(k, super, CHECK_NULL); 55 return k(); 56 } 57 58 59 void constantPoolCacheKlass::oop_follow_contents(oop obj) { 60 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 61 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 62 // Performance tweak: We skip iterating over the klass pointer since we 63 // know that Universe::constantPoolCacheKlassObj never moves. 64 // gc of constant pool cache instance variables 65 MarkSweep::mark_and_push((oop*)cache->constant_pool_addr()); 66 // gc of constant pool cache entries 67 int i = cache->length(); 68 while (i-- > 0) cache->entry_at(i)->follow_contents(); 69 } 70 71 #ifndef SERIALGC 72 void constantPoolCacheKlass::oop_follow_contents(ParCompactionManager* cm, 73 oop obj) { 74 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 75 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 76 // Performance tweak: We skip iterating over the klass pointer since we 77 // know that Universe::constantPoolCacheKlassObj never moves. 78 // gc of constant pool cache instance variables 79 PSParallelCompact::mark_and_push(cm, (oop*)cache->constant_pool_addr()); 80 // gc of constant pool cache entries 81 int i = cache->length(); 82 while (i-- > 0) cache->entry_at(i)->follow_contents(cm); 83 } 84 #endif // SERIALGC 85 86 87 int constantPoolCacheKlass::oop_oop_iterate(oop obj, OopClosure* blk) { 88 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 89 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 90 // Get size before changing pointers. 91 // Don't call size() or oop_size() since that is a virtual call. 92 int size = cache->object_size(); 93 // Performance tweak: We skip iterating over the klass pointer since we 94 // know that Universe::constantPoolCacheKlassObj never moves. 95 // iteration over constant pool cache instance variables 96 blk->do_oop((oop*)cache->constant_pool_addr()); 97 // iteration over constant pool cache entries 98 for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->oop_iterate(blk); 99 return size; 100 } 101 102 103 int constantPoolCacheKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) { 104 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 105 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 106 // Get size before changing pointers. 107 // Don't call size() or oop_size() since that is a virtual call. 108 int size = cache->object_size(); 109 // Performance tweak: We skip iterating over the klass pointer since we 110 // know that Universe::constantPoolCacheKlassObj never moves. 111 // iteration over constant pool cache instance variables 112 oop* addr = (oop*)cache->constant_pool_addr(); 113 if (mr.contains(addr)) blk->do_oop(addr); 114 // iteration over constant pool cache entries 115 for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->oop_iterate_m(blk, mr); 116 return size; 117 } 118 119 120 int constantPoolCacheKlass::oop_adjust_pointers(oop obj) { 121 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 122 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 123 // Get size before changing pointers. 124 // Don't call size() or oop_size() since that is a virtual call. 125 int size = cache->object_size(); 126 // Performance tweak: We skip iterating over the klass pointer since we 127 // know that Universe::constantPoolCacheKlassObj never moves. 128 // Iteration over constant pool cache instance variables 129 MarkSweep::adjust_pointer((oop*)cache->constant_pool_addr()); 130 // iteration over constant pool cache entries 131 for (int i = 0; i < cache->length(); i++) 132 cache->entry_at(i)->adjust_pointers(); 133 return size; 134 } 135 136 #ifndef SERIALGC 137 void constantPoolCacheKlass::oop_copy_contents(PSPromotionManager* pm, 138 oop obj) { 139 assert(obj->is_constantPoolCache(), "should be constant pool"); 140 } 141 142 void constantPoolCacheKlass::oop_push_contents(PSPromotionManager* pm, 143 oop obj) { 144 assert(obj->is_constantPoolCache(), "should be constant pool"); 145 } 146 147 int 148 constantPoolCacheKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { 149 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 150 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 151 152 // Iteration over constant pool cache instance variables 153 PSParallelCompact::adjust_pointer((oop*)cache->constant_pool_addr()); 154 155 // iteration over constant pool cache entries 156 for (int i = 0; i < cache->length(); ++i) { 157 cache->entry_at(i)->update_pointers(); 158 } 159 160 return cache->object_size(); 161 } 162 163 int 164 constantPoolCacheKlass::oop_update_pointers(ParCompactionManager* cm, oop obj, 165 HeapWord* beg_addr, 166 HeapWord* end_addr) { 167 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 168 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 169 170 // Iteration over constant pool cache instance variables 171 oop* p; 172 p = (oop*)cache->constant_pool_addr(); 173 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr); 174 175 // Iteration over constant pool cache entries 176 for (int i = 0; i < cache->length(); ++i) { 177 cache->entry_at(i)->update_pointers(beg_addr, end_addr); 178 } 179 return cache->object_size(); 180 } 181 #endif // SERIALGC 182 183 #ifndef PRODUCT 184 185 void constantPoolCacheKlass::oop_print_on(oop obj, outputStream* st) { 186 assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); 187 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 188 // super print 189 arrayKlass::oop_print_on(obj, st); 190 // print constant pool cache entries 191 for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->print(st, i); 192 } 193 194 #endif 195 196 void constantPoolCacheKlass::oop_verify_on(oop obj, outputStream* st) { 197 guarantee(obj->is_constantPoolCache(), "obj must be constant pool cache"); 198 constantPoolCacheOop cache = (constantPoolCacheOop)obj; 199 // super verify 200 arrayKlass::oop_verify_on(obj, st); 201 // print constant pool cache entries 202 for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->verify(st); 203 } 204 205 206 const char* constantPoolCacheKlass::internal_name() const { 207 return "{constant pool cache}"; 208 } 209