Path: blob/master/src/hotspot/share/oops/instanceMirrorKlass.cpp
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#include "precompiled.hpp"25#include "classfile/javaClasses.inline.hpp"26#include "gc/shared/collectedHeap.inline.hpp"27#include "memory/iterator.inline.hpp"28#include "memory/oopFactory.hpp"29#include "memory/universe.hpp"30#include "oops/instanceKlass.hpp"31#include "oops/instanceMirrorKlass.hpp"32#include "oops/instanceOop.hpp"33#include "oops/oop.inline.hpp"34#include "oops/symbol.hpp"35#include "runtime/handles.inline.hpp"36#include "utilities/macros.hpp"3738int InstanceMirrorKlass::_offset_of_static_fields = 0;3940int InstanceMirrorKlass::instance_size(Klass* k) {41if (k != NULL && k->is_instance_klass()) {42return align_object_size(size_helper() + InstanceKlass::cast(k)->static_field_size());43}44return size_helper();45}4647instanceOop InstanceMirrorKlass::allocate_instance(Klass* k, TRAPS) {48// Query before forming handle.49int size = instance_size(k);50assert(size > 0, "total object size must be positive: %d", size);5152// Since mirrors can be variable sized because of the static fields, store53// the size in the mirror itself.54return (instanceOop)Universe::heap()->class_allocate(this, size, THREAD);55}5657int InstanceMirrorKlass::oop_size(oop obj) const {58return java_lang_Class::oop_size_raw(obj);59}6061int InstanceMirrorKlass::compute_static_oop_field_count(oop obj) {62Klass* k = java_lang_Class::as_Klass(obj);63if (k != NULL && k->is_instance_klass()) {64return InstanceKlass::cast(k)->static_oop_field_count();65}66return 0;67}6869#if INCLUDE_CDS70void InstanceMirrorKlass::serialize_offsets(SerializeClosure* f) {71f->do_u4((u4*)&_offset_of_static_fields);72}73#endif747576