Path: blob/master/src/hotspot/share/oops/instanceMirrorKlass.inline.hpp
40951 views
/*1* Copyright (c) 2015, 2020, 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_INLINE_HPP25#define SHARE_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP2627#include "oops/instanceMirrorKlass.hpp"2829#include "classfile/javaClasses.hpp"30#include "oops/instanceKlass.inline.hpp"31#include "oops/klass.hpp"32#include "oops/oop.inline.hpp"33#include "utilities/debug.hpp"34#include "utilities/globalDefinitions.hpp"35#include "utilities/macros.hpp"3637template <typename T, class OopClosureType>38void InstanceMirrorKlass::oop_oop_iterate_statics(oop obj, OopClosureType* closure) {39T* p = (T*)start_of_static_fields(obj);40T* const end = p + java_lang_Class::static_oop_field_count_raw(obj);4142for (; p < end; ++p) {43Devirtualizer::do_oop(closure, p);44}45}4647template <typename T, class OopClosureType>48void InstanceMirrorKlass::oop_oop_iterate(oop obj, OopClosureType* closure) {49InstanceKlass::oop_oop_iterate<T>(obj, closure);5051if (Devirtualizer::do_metadata(closure)) {52Klass* klass = java_lang_Class::as_Klass_raw(obj);53// We'll get NULL for primitive mirrors.54if (klass != NULL) {55if (klass->class_loader_data() == NULL) {56// This is a mirror that belongs to a shared class that has not be loaded yet.57// It's only reachable via HeapShared::roots(). All of its fields should be zero58// so there's no need to scan.59assert(klass->is_shared(), "must be");60return;61} else if (klass->is_instance_klass() && klass->class_loader_data()->has_class_mirror_holder()) {62// A non-strong hidden class doesn't have its own class loader,63// so when handling the java mirror for the class we need to make sure its class64// loader data is claimed, this is done by calling do_cld explicitly.65// For non-strong hidden classes the call to do_cld is made when the class66// loader itself is handled.67Devirtualizer::do_cld(closure, klass->class_loader_data());68} else {69Devirtualizer::do_klass(closure, klass);70}71} else {72// We would like to assert here (as below) that if klass has been NULL, then73// this has been a mirror for a primitive type that we do not need to follow74// as they are always strong roots.75// However, we might get across a klass that just changed during CMS concurrent76// marking if allocation occurred in the old generation.77// This is benign here, as we keep alive all CLDs that were loaded during the78// CMS concurrent phase in the class loading, i.e. they will be iterated over79// and kept alive during remark.80// assert(java_lang_Class::is_primitive(obj), "Sanity check");81}82}8384oop_oop_iterate_statics<T>(obj, closure);85}8687template <typename T, class OopClosureType>88void InstanceMirrorKlass::oop_oop_iterate_reverse(oop obj, OopClosureType* closure) {89InstanceKlass::oop_oop_iterate_reverse<T>(obj, closure);9091InstanceMirrorKlass::oop_oop_iterate_statics<T>(obj, closure);92}9394template <typename T, class OopClosureType>95void InstanceMirrorKlass::oop_oop_iterate_statics_bounded(oop obj,96OopClosureType* closure,97MemRegion mr) {98T* p = (T*)start_of_static_fields(obj);99T* end = p + java_lang_Class::static_oop_field_count_raw(obj);100101T* const l = (T*)mr.start();102T* const h = (T*)mr.end();103assert(mask_bits((intptr_t)l, sizeof(T)-1) == 0 &&104mask_bits((intptr_t)h, sizeof(T)-1) == 0,105"bounded region must be properly aligned");106107if (p < l) {108p = l;109}110if (end > h) {111end = h;112}113114for (;p < end; ++p) {115Devirtualizer::do_oop(closure, p);116}117}118119template <typename T, class OopClosureType>120void InstanceMirrorKlass::oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr) {121InstanceKlass::oop_oop_iterate_bounded<T>(obj, closure, mr);122123if (Devirtualizer::do_metadata(closure)) {124if (mr.contains(obj)) {125Klass* klass = java_lang_Class::as_Klass_raw(obj);126// We'll get NULL for primitive mirrors.127if (klass != NULL) {128Devirtualizer::do_klass(closure, klass);129}130}131}132133oop_oop_iterate_statics_bounded<T>(obj, closure, mr);134}135136#endif // SHARE_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP137138139