1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_MEMORY_METASPACE_ITERATOR_HPP 26 #define SHARE_VM_MEMORY_METASPACE_ITERATOR_HPP 27 28 #include "logging/log.hpp" 29 #include "memory/allocation.hpp" 30 #include "oops/array.hpp" 31 #include "utilities/growableArray.hpp" 32 #include "utilities/resourceHash.hpp" 33 34 // The metadata hierarchy is separate from the oop hierarchy 35 class MetaspaceObj; // no C++ vtable 36 //class Array; // no C++ vtable 37 class Annotations; // no C++ vtable 38 class ConstantPoolCache; // no C++ vtable 39 class ConstMethod; // no C++ vtable 40 class MethodCounters; // no C++ vtable 41 class Symbol; // no C++ vtable 42 class Metadata; // has C++ vtable (so do all subclasses) 43 class ConstantPool; 44 class MethodData; 45 class Method; 46 class Klass; 47 class InstanceKlass; 48 class InstanceMirrorKlass; 49 class InstanceClassLoaderKlass; 50 class InstanceRefKlass; 51 class ArrayKlass; 52 class ObjArrayKlass; 247 PrimitiveArrayRef<T> ref(mpp); 248 push_impl(&ref, w); 249 } 250 251 // If the above function doesn't match (mpp is not an Array<> type), then 252 // this will be matched by default. 253 template <class T> void push(T** mpp, Writability w = _default) { 254 ObjectRef<T> ref(mpp); 255 push_impl(&ref, w); 256 } 257 }; 258 259 // This is a special MetaspaceClosure that visits each unique MetaspaceObj once. 260 class UniqueMetaspaceClosure : public MetaspaceClosure { 261 // Do not override. Returns true if we are discovering ref->obj() for the first time. 262 virtual bool do_ref(Ref* ref, bool read_only); 263 264 public: 265 // Gets called the first time we discover an object. 266 virtual void do_unique_ref(Ref* ref, bool read_only) = 0; 267 private: 268 static unsigned my_hash(const address& a) { 269 return primitive_hash<address>(a); 270 } 271 static bool my_equals(const address& a0, const address& a1) { 272 return primitive_equals<address>(a0, a1); 273 } 274 ResourceHashtable< 275 address, bool, 276 UniqueMetaspaceClosure::my_hash, // solaris compiler doesn't like: primitive_hash<address> 277 UniqueMetaspaceClosure::my_equals, // solaris compiler doesn't like: primitive_equals<address> 278 15889, // prime number 279 ResourceObj::C_HEAP> _has_been_visited; 280 }; 281 282 #endif // SHARE_VM_MEMORY_METASPACE_ITERATOR_HPP | 1 /* 2 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_MEMORY_METASPACE_ITERATOR_HPP 26 #define SHARE_VM_MEMORY_METASPACE_ITERATOR_HPP 27 28 #include "logging/log.hpp" 29 #include "memory/allocation.hpp" 30 #include "oops/array.hpp" 31 #include "utilities/growableArray.hpp" 32 #include "utilities/hashtable.inline.hpp" 33 34 // The metadata hierarchy is separate from the oop hierarchy 35 class MetaspaceObj; // no C++ vtable 36 //class Array; // no C++ vtable 37 class Annotations; // no C++ vtable 38 class ConstantPoolCache; // no C++ vtable 39 class ConstMethod; // no C++ vtable 40 class MethodCounters; // no C++ vtable 41 class Symbol; // no C++ vtable 42 class Metadata; // has C++ vtable (so do all subclasses) 43 class ConstantPool; 44 class MethodData; 45 class Method; 46 class Klass; 47 class InstanceKlass; 48 class InstanceMirrorKlass; 49 class InstanceClassLoaderKlass; 50 class InstanceRefKlass; 51 class ArrayKlass; 52 class ObjArrayKlass; 247 PrimitiveArrayRef<T> ref(mpp); 248 push_impl(&ref, w); 249 } 250 251 // If the above function doesn't match (mpp is not an Array<> type), then 252 // this will be matched by default. 253 template <class T> void push(T** mpp, Writability w = _default) { 254 ObjectRef<T> ref(mpp); 255 push_impl(&ref, w); 256 } 257 }; 258 259 // This is a special MetaspaceClosure that visits each unique MetaspaceObj once. 260 class UniqueMetaspaceClosure : public MetaspaceClosure { 261 // Do not override. Returns true if we are discovering ref->obj() for the first time. 262 virtual bool do_ref(Ref* ref, bool read_only); 263 264 public: 265 // Gets called the first time we discover an object. 266 virtual void do_unique_ref(Ref* ref, bool read_only) = 0; 267 UniqueMetaspaceClosure() : _has_been_visited(15889) {} 268 269 private: 270 KVHashtable<address, bool, mtInternal> _has_been_visited; 271 }; 272 273 #endif // SHARE_VM_MEMORY_METASPACE_ITERATOR_HPP |