Path: blob/master/src/hotspot/share/oops/instanceMirrorKlass.hpp
40951 views
/*1* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_OOPS_INSTANCEMIRRORKLASS_HPP25#define SHARE_OOPS_INSTANCEMIRRORKLASS_HPP2627#include "classfile/vmClasses.hpp"28#include "oops/instanceKlass.hpp"29#include "runtime/handles.hpp"30#include "utilities/macros.hpp"3132class ClassFileParser;3334// An InstanceMirrorKlass is a specialized InstanceKlass for35// java.lang.Class instances. These instances are special because36// they contain the static fields of the class in addition to the37// normal fields of Class. This means they are variable sized38// instances and need special logic for computing their size and for39// iteration of their oops.404142class InstanceMirrorKlass: public InstanceKlass {43friend class VMStructs;44friend class InstanceKlass;4546public:47static const KlassID ID = InstanceMirrorKlassID;4849private:50static int _offset_of_static_fields;5152InstanceMirrorKlass(const ClassFileParser& parser) : InstanceKlass(parser, InstanceKlass::_kind_mirror, ID) {}5354public:55InstanceMirrorKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }5657static InstanceMirrorKlass* cast(Klass* k) {58return const_cast<InstanceMirrorKlass*>(cast(const_cast<const Klass*>(k)));59}6061static const InstanceMirrorKlass* cast(const Klass* k) {62assert(InstanceKlass::cast(k)->is_mirror_instance_klass(), "cast to InstanceMirrorKlass");63return static_cast<const InstanceMirrorKlass*>(k);64}6566// Returns the size of the instance including the extra static fields.67virtual int oop_size(oop obj) const;6869// Static field offset is an offset into the Heap, should be converted by70// based on UseCompressedOop for traversal71static HeapWord* start_of_static_fields(oop obj) {72return (HeapWord*)(cast_from_oop<intptr_t>(obj) + offset_of_static_fields());73}7475static void init_offset_of_static_fields() {76// Cache the offset of the static fields in the Class instance77assert(_offset_of_static_fields == 0, "once");78_offset_of_static_fields = InstanceMirrorKlass::cast(vmClasses::Class_klass())->size_helper() << LogHeapWordSize;79}8081static int offset_of_static_fields() {82return _offset_of_static_fields;83}8485int compute_static_oop_field_count(oop obj);8687// Given a Klass return the size of the instance88int instance_size(Klass* k);8990// allocation91instanceOop allocate_instance(Klass* k, TRAPS);9293static void serialize_offsets(class SerializeClosure* f) NOT_CDS_RETURN;9495// Oop fields (and metadata) iterators96//97// The InstanceMirrorKlass iterators also visit the hidden Klass pointer.9899// Iterate over the static fields.100template <typename T, class OopClosureType>101inline void oop_oop_iterate_statics(oop obj, OopClosureType* closure);102103// Forward iteration104// Iterate over the oop fields and metadata.105template <typename T, class OopClosureType>106inline void oop_oop_iterate(oop obj, OopClosureType* closure);107108// Reverse iteration109// Iterate over the oop fields and metadata.110template <typename T, class OopClosureType>111inline void oop_oop_iterate_reverse(oop obj, OopClosureType* closure);112113// Bounded range iteration114// Iterate over the oop fields and metadata.115template <typename T, class OopClosureType>116inline void oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr);117118private:119120// Iterate over the static fields.121template <typename T, class OopClosureType>122inline void oop_oop_iterate_statics_bounded(oop obj, OopClosureType* closure, MemRegion mr);123};124125#endif // SHARE_OOPS_INSTANCEMIRRORKLASS_HPP126127128