never@2658: /* coleenp@4037: * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. never@2658: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. never@2658: * never@2658: * This code is free software; you can redistribute it and/or modify it never@2658: * under the terms of the GNU General Public License version 2 only, as never@2658: * published by the Free Software Foundation. never@2658: * never@2658: * This code is distributed in the hope that it will be useful, but WITHOUT never@2658: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or never@2658: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License never@2658: * version 2 for more details (a copy is included in the LICENSE file that never@2658: * accompanied this code). never@2658: * never@2658: * You should have received a copy of the GNU General Public License version never@2658: * 2 along with this work; if not, write to the Free Software Foundation, never@2658: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. never@2658: * never@2658: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA never@2658: * or visit www.oracle.com if you need additional information or have any never@2658: * questions. never@2658: * never@2658: */ never@2658: never@2658: #ifndef SHARE_VM_OOPS_INSTANCEMIRRORKLASS_HPP never@2658: #define SHARE_VM_OOPS_INSTANCEMIRRORKLASS_HPP never@2658: coleenp@4037: #include "classfile/systemDictionary.hpp" never@2658: #include "oops/instanceKlass.hpp" coleenp@4037: #include "runtime/handles.hpp" never@2658: coleenp@4047: // An InstanceMirrorKlass is a specialized InstanceKlass for never@2658: // java.lang.Class instances. These instances are special because never@2658: // they contain the static fields of the class in addition to the never@2658: // normal fields of Class. This means they are variable sized never@2658: // instances and need special logic for computing their size and for never@2658: // iteration of their oops. never@2658: never@2658: coleenp@4047: class InstanceMirrorKlass: public InstanceKlass { never@2693: friend class VMStructs; coleenp@4037: friend class InstanceKlass; never@2693: never@2658: private: never@2658: static int _offset_of_static_fields; never@2658: coleenp@4037: // Constructor coleenp@4047: InstanceMirrorKlass(int vtable_len, int itable_len, int static_field_size, int nonstatic_oop_map_size, ReferenceType rt, AccessFlags access_flags, bool is_anonymous) coleenp@4037: : InstanceKlass(vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, access_flags, is_anonymous) {} coleenp@4037: never@2658: public: coleenp@4047: InstanceMirrorKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); } never@2658: // Type testing never@2658: bool oop_is_instanceMirror() const { return true; } never@2658: coleenp@4037: // Casting from Klass* coleenp@4047: static InstanceMirrorKlass* cast(Klass* k) { coleenp@4047: assert(k->oop_is_instanceMirror(), "cast to InstanceMirrorKlass"); coleenp@4047: return (InstanceMirrorKlass*) k; never@2658: } never@2658: never@2658: // Returns the size of the instance including the extra static fields. never@2658: virtual int oop_size(oop obj) const; never@2658: never@2658: // Static field offset is an offset into the Heap, should be converted by never@2658: // based on UseCompressedOop for traversal never@2658: static HeapWord* start_of_static_fields(oop obj) { never@2658: return (HeapWord*)((intptr_t)obj + offset_of_static_fields()); never@2658: } never@2658: never@2658: static void init_offset_of_static_fields() { never@2658: // Cache the offset of the static fields in the Class instance never@2658: assert(_offset_of_static_fields == 0, "once"); coleenp@4047: _offset_of_static_fields = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->size_helper() << LogHeapWordSize; never@2658: } never@2658: never@2658: static int offset_of_static_fields() { never@2658: return _offset_of_static_fields; never@2658: } never@2658: never@2658: int compute_static_oop_field_count(oop obj); never@2658: never@2658: // Given a Klass return the size of the instance never@2658: int instance_size(KlassHandle k); never@2658: never@2658: // allocation never@2658: instanceOop allocate_instance(KlassHandle k, TRAPS); never@2658: never@2658: // Garbage collection never@2658: int oop_adjust_pointers(oop obj); never@2658: void oop_follow_contents(oop obj); never@2658: never@2658: // Parallel Scavenge and Parallel Old never@2658: PARALLEL_GC_DECLS never@2658: coleenp@4037: int oop_oop_iterate(oop obj, ExtendedOopClosure* blk) { never@2658: return oop_oop_iterate_v(obj, blk); never@2658: } coleenp@4037: int oop_oop_iterate_m(oop obj, ExtendedOopClosure* blk, MemRegion mr) { never@2658: return oop_oop_iterate_v_m(obj, blk, mr); never@2658: } never@2658: never@2658: #define InstanceMirrorKlass_OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \ never@2658: int oop_oop_iterate##nv_suffix(oop obj, OopClosureType* blk); \ never@2658: int oop_oop_iterate##nv_suffix##_m(oop obj, OopClosureType* blk, MemRegion mr); never@2658: never@2658: ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceMirrorKlass_OOP_OOP_ITERATE_DECL) never@2658: ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceMirrorKlass_OOP_OOP_ITERATE_DECL) never@2658: never@2658: #ifndef SERIALGC never@2658: #define InstanceMirrorKlass_OOP_OOP_ITERATE_BACKWARDS_DECL(OopClosureType, nv_suffix) \ never@2658: int oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* blk); never@2658: never@2658: ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceMirrorKlass_OOP_OOP_ITERATE_BACKWARDS_DECL) never@2658: ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceMirrorKlass_OOP_OOP_ITERATE_BACKWARDS_DECL) never@2658: #endif // !SERIALGC never@2658: }; never@2658: never@2658: #endif // SHARE_VM_OOPS_INSTANCEMIRRORKLASS_HPP