duke@435: /* stefank@2314: * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "classfile/javaClasses.hpp" stefank@2314: #include "gc_implementation/shared/markSweep.inline.hpp" stefank@2314: #include "gc_interface/collectedHeap.hpp" stefank@2314: #include "interpreter/bytecodes.hpp" stefank@2314: #include "memory/genOopClosures.inline.hpp" stefank@2314: #include "memory/permGen.hpp" stefank@2314: #include "oops/constantPoolOop.hpp" stefank@2314: #include "oops/cpCacheKlass.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "runtime/handles.inline.hpp" stefank@2314: #ifndef SERIALGC stefank@2314: #include "gc_implementation/parNew/parOopClosures.inline.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" stefank@2314: #include "memory/cardTableRS.hpp" stefank@2314: #include "oops/oop.pcgc.inline.hpp" stefank@2314: #endif duke@435: duke@435: duke@435: int constantPoolCacheKlass::oop_size(oop obj) const { duke@435: assert(obj->is_constantPoolCache(), "must be constantPool"); duke@435: return constantPoolCacheOop(obj)->object_size(); duke@435: } duke@435: duke@435: jmasa@977: constantPoolCacheOop constantPoolCacheKlass::allocate(int length, jmasa@977: bool is_conc_safe, jmasa@977: TRAPS) { duke@435: // allocate memory duke@435: int size = constantPoolCacheOopDesc::object_size(length); jmasa@977: duke@435: KlassHandle klass (THREAD, as_klassOop()); jmasa@977: jmasa@977: // This is the original code. The code from permanent_obj_allocate() jmasa@977: // was in-lined to allow the setting of is_conc_safe before the klass jmasa@977: // is installed. jmasa@977: // constantPoolCacheOop cache = (constantPoolCacheOop) jmasa@977: // CollectedHeap::permanent_obj_allocate(klass, size, CHECK_NULL); jmasa@977: jmasa@977: oop obj = CollectedHeap::permanent_obj_allocate_no_klass_install(klass, size, CHECK_NULL); jmasa@977: constantPoolCacheOop cache = (constantPoolCacheOop) obj; jmasa@977: cache->set_is_conc_safe(is_conc_safe); jmasa@977: // The store to is_conc_safe must be visible before the klass jmasa@977: // is set. This should be done safely because _is_conc_safe has jmasa@977: // been declared volatile. If there are any problems, consider adding jmasa@977: // OrderAccess::storestore(); jmasa@977: CollectedHeap::post_allocation_install_obj_klass(klass, obj, size); jmasa@977: NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value((HeapWord*) obj, jmasa@977: size)); jmasa@977: jmasa@977: // The length field affects the size of the object. The allocation jmasa@977: // above allocates the correct size (see calculation of "size") but jmasa@977: // the size() method of the constant pool cache oop will not reflect jmasa@977: // that size until the correct length is set. coleenp@548: cache->set_length(length); jmasa@977: jmasa@977: // The store of the length must be visible before is_conc_safe is jmasa@977: // set to a safe state. jmasa@977: // This should be done safely because _is_conc_safe has jmasa@977: // been declared volatile. If there are any problems, consider adding jmasa@977: // OrderAccess::storestore(); jmasa@977: cache->set_is_conc_safe(methodOopDesc::IsSafeConc); duke@435: cache->set_constant_pool(NULL); duke@435: return cache; duke@435: } duke@435: duke@435: klassOop constantPoolCacheKlass::create_klass(TRAPS) { duke@435: constantPoolCacheKlass o; coleenp@548: KlassHandle h_this_klass(THREAD, Universe::klassKlassObj()); coleenp@548: KlassHandle k = base_create_klass(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL); coleenp@548: // Make sure size calculation is right coleenp@548: assert(k()->size() == align_object_size(header_size()), "wrong size for object"); coleenp@548: java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror duke@435: return k(); duke@435: } duke@435: duke@435: duke@435: void constantPoolCacheKlass::oop_follow_contents(oop obj) { duke@435: assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); duke@435: constantPoolCacheOop cache = (constantPoolCacheOop)obj; duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::constantPoolCacheKlassObj never moves. duke@435: // gc of constant pool cache instance variables duke@435: MarkSweep::mark_and_push((oop*)cache->constant_pool_addr()); duke@435: // gc of constant pool cache entries duke@435: int i = cache->length(); duke@435: while (i-- > 0) cache->entry_at(i)->follow_contents(); duke@435: } duke@435: duke@435: #ifndef SERIALGC duke@435: void constantPoolCacheKlass::oop_follow_contents(ParCompactionManager* cm, duke@435: oop obj) { duke@435: assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); duke@435: constantPoolCacheOop cache = (constantPoolCacheOop)obj; duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::constantPoolCacheKlassObj never moves. duke@435: // gc of constant pool cache instance variables duke@435: PSParallelCompact::mark_and_push(cm, (oop*)cache->constant_pool_addr()); duke@435: // gc of constant pool cache entries duke@435: int i = cache->length(); duke@435: while (i-- > 0) cache->entry_at(i)->follow_contents(cm); duke@435: } duke@435: #endif // SERIALGC duke@435: duke@435: duke@435: int constantPoolCacheKlass::oop_oop_iterate(oop obj, OopClosure* blk) { duke@435: assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); duke@435: constantPoolCacheOop cache = (constantPoolCacheOop)obj; duke@435: // Get size before changing pointers. duke@435: // Don't call size() or oop_size() since that is a virtual call. duke@435: int size = cache->object_size(); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::constantPoolCacheKlassObj never moves. duke@435: // iteration over constant pool cache instance variables duke@435: blk->do_oop((oop*)cache->constant_pool_addr()); duke@435: // iteration over constant pool cache entries duke@435: for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->oop_iterate(blk); duke@435: return size; duke@435: } duke@435: duke@435: duke@435: int constantPoolCacheKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) { duke@435: assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); duke@435: constantPoolCacheOop cache = (constantPoolCacheOop)obj; duke@435: // Get size before changing pointers. duke@435: // Don't call size() or oop_size() since that is a virtual call. duke@435: int size = cache->object_size(); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::constantPoolCacheKlassObj never moves. duke@435: // iteration over constant pool cache instance variables duke@435: oop* addr = (oop*)cache->constant_pool_addr(); duke@435: if (mr.contains(addr)) blk->do_oop(addr); duke@435: // iteration over constant pool cache entries duke@435: for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->oop_iterate_m(blk, mr); duke@435: return size; duke@435: } duke@435: duke@435: int constantPoolCacheKlass::oop_adjust_pointers(oop obj) { duke@435: assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); duke@435: constantPoolCacheOop cache = (constantPoolCacheOop)obj; duke@435: // Get size before changing pointers. duke@435: // Don't call size() or oop_size() since that is a virtual call. duke@435: int size = cache->object_size(); duke@435: // Performance tweak: We skip iterating over the klass pointer since we duke@435: // know that Universe::constantPoolCacheKlassObj never moves. duke@435: // Iteration over constant pool cache instance variables duke@435: MarkSweep::adjust_pointer((oop*)cache->constant_pool_addr()); duke@435: // iteration over constant pool cache entries duke@435: for (int i = 0; i < cache->length(); i++) duke@435: cache->entry_at(i)->adjust_pointers(); duke@435: return size; duke@435: } duke@435: jmasa@977: bool constantPoolCacheKlass::oop_is_conc_safe(oop obj) const { jmasa@981: assert(obj->is_constantPoolCache(), "should be constant pool"); jmasa@977: return constantPoolCacheOop(obj)->is_conc_safe(); jmasa@977: } jmasa@977: duke@435: #ifndef SERIALGC duke@435: void constantPoolCacheKlass::oop_push_contents(PSPromotionManager* pm, duke@435: oop obj) { duke@435: assert(obj->is_constantPoolCache(), "should be constant pool"); jrose@1161: if (EnableInvokeDynamic) { jrose@1161: constantPoolCacheOop cache = (constantPoolCacheOop)obj; jrose@1161: // during a scavenge, it is safe to inspect my pool, since it is perm jrose@1161: constantPoolOop pool = cache->constant_pool(); jrose@1161: assert(pool->is_constantPool(), "should be constant pool"); jrose@1161: if (pool->has_invokedynamic()) { jrose@1161: for (int i = 0; i < cache->length(); i++) { jrose@1161: ConstantPoolCacheEntry* e = cache->entry_at(i); jrose@1161: oop* p = (oop*)&e->_f1; jrose@1161: if (e->is_secondary_entry()) { jrose@1161: if (PSScavenge::should_scavenge(p)) jrose@1161: pm->claim_or_forward_depth(p); jrose@1161: assert(!(e->is_vfinal() && PSScavenge::should_scavenge((oop*)&e->_f2)), jrose@1161: "no live oops here"); jrose@1161: } jrose@1161: } jrose@1161: } jrose@1161: } duke@435: } duke@435: duke@435: int duke@435: constantPoolCacheKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { duke@435: assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); duke@435: constantPoolCacheOop cache = (constantPoolCacheOop)obj; duke@435: duke@435: // Iteration over constant pool cache instance variables duke@435: PSParallelCompact::adjust_pointer((oop*)cache->constant_pool_addr()); duke@435: duke@435: // iteration over constant pool cache entries duke@435: for (int i = 0; i < cache->length(); ++i) { duke@435: cache->entry_at(i)->update_pointers(); duke@435: } duke@435: duke@435: return cache->object_size(); duke@435: } duke@435: duke@435: int duke@435: constantPoolCacheKlass::oop_update_pointers(ParCompactionManager* cm, oop obj, duke@435: HeapWord* beg_addr, duke@435: HeapWord* end_addr) { duke@435: assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); duke@435: constantPoolCacheOop cache = (constantPoolCacheOop)obj; duke@435: duke@435: // Iteration over constant pool cache instance variables duke@435: oop* p; duke@435: p = (oop*)cache->constant_pool_addr(); duke@435: PSParallelCompact::adjust_pointer(p, beg_addr, end_addr); duke@435: duke@435: // Iteration over constant pool cache entries duke@435: for (int i = 0; i < cache->length(); ++i) { duke@435: cache->entry_at(i)->update_pointers(beg_addr, end_addr); duke@435: } duke@435: return cache->object_size(); duke@435: } duke@435: #endif // SERIALGC duke@435: duke@435: void constantPoolCacheKlass::oop_print_on(oop obj, outputStream* st) { duke@435: assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); duke@435: constantPoolCacheOop cache = (constantPoolCacheOop)obj; duke@435: // super print coleenp@548: Klass::oop_print_on(obj, st); duke@435: // print constant pool cache entries duke@435: for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->print(st, i); duke@435: } duke@435: jrose@1590: void constantPoolCacheKlass::oop_print_value_on(oop obj, outputStream* st) { jrose@1590: assert(obj->is_constantPoolCache(), "obj must be constant pool cache"); jrose@1590: constantPoolCacheOop cache = (constantPoolCacheOop)obj; jrose@1590: st->print("cache [%d]", cache->length()); jrose@1590: cache->print_address_on(st); jrose@1590: st->print(" for "); jrose@1590: cache->constant_pool()->print_value_on(st); jrose@1590: } jrose@1590: duke@435: void constantPoolCacheKlass::oop_verify_on(oop obj, outputStream* st) { duke@435: guarantee(obj->is_constantPoolCache(), "obj must be constant pool cache"); duke@435: constantPoolCacheOop cache = (constantPoolCacheOop)obj; duke@435: // super verify coleenp@548: Klass::oop_verify_on(obj, st); duke@435: // print constant pool cache entries duke@435: for (int i = 0; i < cache->length(); i++) cache->entry_at(i)->verify(st); duke@435: } duke@435: duke@435: duke@435: const char* constantPoolCacheKlass::internal_name() const { duke@435: return "{constant pool cache}"; duke@435: }