src/hotspot/share/memory/metaspaceClosure.hpp
changeset 52631 3009ca99de32
parent 47216 71c04702a3d5
child 53244 9807daeb47c4
equal deleted inserted replaced
52630:68d450652337 52631:3009ca99de32
     1 /*
     1 /*
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    27 
    27 
    28 #include "logging/log.hpp"
    28 #include "logging/log.hpp"
    29 #include "memory/allocation.hpp"
    29 #include "memory/allocation.hpp"
    30 #include "oops/array.hpp"
    30 #include "oops/array.hpp"
    31 #include "utilities/growableArray.hpp"
    31 #include "utilities/growableArray.hpp"
    32 #include "utilities/resourceHash.hpp"
    32 #include "utilities/hashtable.inline.hpp"
    33 
    33 
    34 // The metadata hierarchy is separate from the oop hierarchy
    34 // The metadata hierarchy is separate from the oop hierarchy
    35   class MetaspaceObj;        // no C++ vtable
    35   class MetaspaceObj;        // no C++ vtable
    36 //class   Array;             // no C++ vtable
    36 //class   Array;             // no C++ vtable
    37   class   Annotations;       // no C++ vtable
    37   class   Annotations;       // no C++ vtable
   256   }
   256   }
   257 };
   257 };
   258 
   258 
   259 // This is a special MetaspaceClosure that visits each unique MetaspaceObj once.
   259 // This is a special MetaspaceClosure that visits each unique MetaspaceObj once.
   260 class UniqueMetaspaceClosure : public MetaspaceClosure {
   260 class UniqueMetaspaceClosure : public MetaspaceClosure {
       
   261   static const int INITIAL_TABLE_SIZE = 15889;
       
   262   static const int MAX_TABLE_SIZE     = 1000000;
       
   263 
   261   // Do not override. Returns true if we are discovering ref->obj() for the first time.
   264   // 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);
   265   virtual bool do_ref(Ref* ref, bool read_only);
   263 
   266 
   264 public:
   267 public:
   265   // Gets called the first time we discover an object.
   268   // Gets called the first time we discover an object.
   266   virtual void do_unique_ref(Ref* ref, bool read_only) = 0;
   269   virtual void do_unique_ref(Ref* ref, bool read_only) = 0;
       
   270   UniqueMetaspaceClosure() : _has_been_visited(INITIAL_TABLE_SIZE) {}
       
   271 
   267 private:
   272 private:
   268   static unsigned my_hash(const address& a) {
   273   KVHashtable<address, bool, mtInternal> _has_been_visited;
   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 };
   274 };
   281 
   275 
   282 #endif // SHARE_VM_MEMORY_METASPACE_ITERATOR_HPP
   276 #endif // SHARE_VM_MEMORY_METASPACE_ITERATOR_HPP