1 /* Copyright (c) 2015, 2019, 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 it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 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 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 #ifndef SHARE_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP 25 #define SHARE_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP 26 27 #include "classfile/javaClasses.hpp" 28 #include "oops/instanceKlass.inline.hpp" 29 #include "oops/instanceMirrorKlass.hpp" 30 #include "oops/klass.hpp" 31 #include "oops/oop.inline.hpp" 32 #include "utilities/debug.hpp" 33 #include "utilities/globalDefinitions.hpp" 34 #include "utilities/macros.hpp" 35 36 template <typename T, class OopClosureType> 37 void InstanceMirrorKlass::oop_oop_iterate_statics(oop obj, OopClosureType* closure) { 38 T* p = (T*)start_of_static_fields(obj); 39 T* const end = p + java_lang_Class::static_oop_field_count_raw(obj); 40 41 for (; p < end; ++p) { 42 Devirtualizer::do_oop(closure, p); 43 } 44 } 45 46 template <typename T, class OopClosureType> 47 void InstanceMirrorKlass::oop_oop_iterate(oop obj, OopClosureType* closure) { 48 InstanceKlass::oop_oop_iterate<T>(obj, closure); 49 50 if (Devirtualizer::do_metadata(closure)) { 51 Klass* klass = java_lang_Class::as_Klass_raw(obj); 52 // We'll get NULL for primitive mirrors. 53 if (klass != NULL) { 54 if (klass->is_instance_klass() && 55 InstanceKlass::cast(klass)->is_unsafe_anonymous()) { 56 // An unsafe anonymous class doesn't have its own class loader, so 57 // when handling the java mirror for the class we need to make sure its class 58 // loader data is claimed, this is done by calling do_cld explicitly. 59 // For non-anonymous classes the call to do_cld is made when the class 60 // loader itself is handled. 61 Devirtualizer::do_cld(closure, klass->class_loader_data()); 62 } else { 63 Devirtualizer::do_klass(closure, klass); 64 } 65 } else { 66 // We would like to assert here (as below) that if klass has been NULL, then 67 // this has been a mirror for a primitive type that we do not need to follow 68 // as they are always strong roots. 69 // However, we might get across a klass that just changed during CMS concurrent 70 // marking if allocation occurred in the old generation. 71 // This is benign here, as we keep alive all CLDs that were loaded during the 72 // CMS concurrent phase in the class loading, i.e. they will be iterated over 73 // and kept alive during remark. 74 // assert(java_lang_Class::is_primitive(obj), "Sanity check"); 75 } 76 } 77 78 oop_oop_iterate_statics<T>(obj, closure); 79 } 80 81 template <typename T, class OopClosureType> 82 void InstanceMirrorKlass::oop_oop_iterate_reverse(oop obj, OopClosureType* closure) { 83 InstanceKlass::oop_oop_iterate_reverse<T>(obj, closure); 84 85 InstanceMirrorKlass::oop_oop_iterate_statics<T>(obj, closure); 86 } 87 88 template <typename T, class OopClosureType> 89 void InstanceMirrorKlass::oop_oop_iterate_statics_bounded(oop obj, 90 OopClosureType* closure, 91 MemRegion mr) { 92 T* p = (T*)start_of_static_fields(obj); 93 T* end = p + java_lang_Class::static_oop_field_count_raw(obj); 94 95 T* const l = (T*)mr.start(); 96 T* const h = (T*)mr.end(); 97 assert(mask_bits((intptr_t)l, sizeof(T)-1) == 0 && 98 mask_bits((intptr_t)h, sizeof(T)-1) == 0, 99 "bounded region must be properly aligned"); 100 101 if (p < l) { 102 p = l; 103 } 104 if (end > h) { 105 end = h; 106 } 107 108 for (;p < end; ++p) { 109 Devirtualizer::do_oop(closure, p); 110 } 111 } 112 113 template <typename T, class OopClosureType> 114 void InstanceMirrorKlass::oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr) { 115 InstanceKlass::oop_oop_iterate_bounded<T>(obj, closure, mr); 116 117 if (Devirtualizer::do_metadata(closure)) { 118 if (mr.contains(obj)) { 119 Klass* klass = java_lang_Class::as_Klass_raw(obj); 120 // We'll get NULL for primitive mirrors. 121 if (klass != NULL) { 122 Devirtualizer::do_klass(closure, klass); 123 } 124 } 125 } 126 127 oop_oop_iterate_statics_bounded<T>(obj, closure, mr); 128 } 129 130 #endif // SHARE_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP