hotspot/src/share/vm/memory/metaspaceClosure.hpp
author ccheung
Mon, 28 Aug 2017 15:34:04 -0700
changeset 47103 a993ec29ec75
parent 46746 ea379ebb9447
permissions -rw-r--r--
8186842: Use Java class loaders for creating the CDS archive Reviewed-by: coleenp, jiangli, iklam, mseledtsov Contributed-by: calvin.cheung@oracle.com, ioi.lam@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     1
/*
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     4
 *
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     8
 *
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    13
 * accompanied this code).
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    14
 *
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    18
 *
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    21
 * questions.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    22
 *
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    23
 */
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    24
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    25
#ifndef SHARE_VM_MEMORY_METASPACE_ITERATOR_HPP
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    26
#define SHARE_VM_MEMORY_METASPACE_ITERATOR_HPP
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    27
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    28
#include "logging/log.hpp"
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    29
#include "memory/allocation.hpp"
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    30
#include "oops/array.hpp"
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    31
#include "utilities/growableArray.hpp"
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    32
#include "utilities/resourceHash.hpp"
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    33
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    34
// The metadata hierarchy is separate from the oop hierarchy
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    35
  class MetaspaceObj;        // no C++ vtable
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    36
//class   Array;             // no C++ vtable
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    37
  class   Annotations;       // no C++ vtable
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    38
  class   ConstantPoolCache; // no C++ vtable
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    39
  class   ConstMethod;       // no C++ vtable
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    40
  class   MethodCounters;    // no C++ vtable
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    41
  class   Symbol;            // no C++ vtable
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    42
  class   Metadata;          // has C++ vtable (so do all subclasses)
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    43
  class     ConstantPool;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    44
  class     MethodData;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    45
  class     Method;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    46
  class     Klass;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    47
  class       InstanceKlass;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    48
  class         InstanceMirrorKlass;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    49
  class         InstanceClassLoaderKlass;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    50
  class         InstanceRefKlass;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    51
  class       ArrayKlass;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    52
  class         ObjArrayKlass;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    53
  class         TypeArrayKlass;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    54
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    55
// class MetaspaceClosure --
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    56
//
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    57
// This class is used for iterating the objects in the HotSpot Metaspaces. It
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    58
// provides an API to walk all the reachable objects starting from a set of
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    59
// root references (such as all Klass'es in the SystemDictionary).
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    60
//
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    61
// Currently it is used for compacting the CDS archive by eliminate temporary
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    62
// objects allocated during archive creation time. See ArchiveCompactor in
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    63
// metaspaceShared.cpp for an example.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    64
//
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    65
// To support MetaspaceClosure, each subclass of MetaspaceObj must provide
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    66
// a method of the type void metaspace_pointers_do(MetaspaceClosure*). This method
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    67
// should call MetaspaceClosure::push() on every pointer fields of this
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    68
// class that points to a MetaspaceObj. See Annotations::metaspace_pointers_do()
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    69
// for an example.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    70
class MetaspaceClosure {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    71
public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    72
  enum Writability {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    73
    _writable,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    74
    _not_writable,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    75
    _default
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    76
  };
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    77
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    78
  // class MetaspaceClosure::Ref --
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    79
  //
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    80
  // MetaspaceClosure can be viewed as a very simple type of copying garbage
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    81
  // collector. For it to function properly, it requires each subclass of
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    82
  // MetaspaceObj to provide two methods:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    83
  //
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    84
  //  size_t size();                                 -- to determine how much data to copy
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    85
  //  void metaspace_pointers_do(MetaspaceClosure*); -- to locate all the embedded pointers
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    86
  //
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    87
  // Calling these methods would be trivial if these two were virtual methods.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    88
  // However, to save space, MetaspaceObj has NO vtable. The vtable is introduced
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    89
  // only in the Metadata class.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    90
  //
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    91
  // To work around the lack of a vtable, we use Ref class with templates
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    92
  // (see ObjectRef, PrimitiveArrayRef and PointerArrayRef)
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    93
  // so that we can statically discover the type of a object. The use of Ref
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    94
  // depends on the fact that:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    95
  //
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    96
  // [1] We don't use polymorphic pointers for MetaspaceObj's that are not subclasses
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    97
  //     of Metadata. I.e., we don't do this:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    98
  //     class Klass {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    99
  //         MetaspaceObj *_obj;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   100
  //         Array<int>* foo() { return (Array<int>*)_obj; }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   101
  //         Symbol*     bar() { return (Symbol*)    _obj; }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   102
  //
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   103
  // [2] All Array<T> dimensions are statically declared.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   104
  class Ref {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   105
  protected:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   106
    virtual void** mpp() const = 0;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   107
  public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   108
    virtual bool not_null() const = 0;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   109
    virtual int size() const = 0;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   110
    virtual void metaspace_pointers_do(MetaspaceClosure *it) const = 0;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   111
    virtual void metaspace_pointers_do_at(MetaspaceClosure *it, address new_loc) const = 0;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   112
    virtual MetaspaceObj::Type msotype() const = 0;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   113
    virtual bool is_read_only_by_default() const = 0;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   114
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   115
    address obj() const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   116
      // In some rare cases (see CPSlot in constantPool.hpp) we store some flags in the lowest
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   117
      // 2 bits of a MetaspaceObj pointer. Unmask these when manipulating the pointer.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   118
      uintx p = (uintx)*mpp();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   119
      return (address)(p & (~FLAG_MASK));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   120
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   121
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   122
    void update(address new_loc) const;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   123
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   124
  private:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   125
    static const uintx FLAG_MASK = 0x03;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   126
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   127
    int flag_bits() const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   128
      uintx p = (uintx)*mpp();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   129
      return (int)(p & FLAG_MASK);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   130
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   131
  };
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   132
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   133
private:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   134
  // -------------------------------------------------- ObjectRef
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   135
  template <class T> class ObjectRef : public Ref {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   136
    T** _mpp;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   137
    T* dereference() const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   138
      return *_mpp;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   139
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   140
  protected:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   141
    virtual void** mpp() const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   142
      return (void**)_mpp;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   143
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   144
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   145
  public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   146
    ObjectRef(T** mpp) : _mpp(mpp) {}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   147
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   148
    virtual bool is_read_only_by_default() const { return T::is_read_only_by_default(); }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   149
    virtual bool not_null()                const { return dereference() != NULL; }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   150
    virtual int size()                     const { return dereference()->size(); }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   151
    virtual MetaspaceObj::Type msotype()   const { return dereference()->type(); }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   152
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   153
    virtual void metaspace_pointers_do(MetaspaceClosure *it) const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   154
      dereference()->metaspace_pointers_do(it);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   155
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   156
    virtual void metaspace_pointers_do_at(MetaspaceClosure *it, address new_loc) const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   157
      ((T*)new_loc)->metaspace_pointers_do(it);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   158
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   159
  };
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   160
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   161
  // -------------------------------------------------- PrimitiveArrayRef
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   162
  template <class T> class PrimitiveArrayRef : public Ref {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   163
    Array<T>** _mpp;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   164
    Array<T>* dereference() const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   165
      return *_mpp;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   166
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   167
  protected:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   168
    virtual void** mpp() const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   169
      return (void**)_mpp;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   170
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   171
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   172
  public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   173
    PrimitiveArrayRef(Array<T>** mpp) : _mpp(mpp) {}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   174
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   175
    // all Arrays are read-only by default
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   176
    virtual bool is_read_only_by_default() const { return true; }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   177
    virtual bool not_null()                const { return dereference() != NULL;  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   178
    virtual int size()                     const { return dereference()->size(); }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   179
    virtual MetaspaceObj::Type msotype()   const { return MetaspaceObj::array_type(sizeof(T)); }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   180
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   181
    virtual void metaspace_pointers_do(MetaspaceClosure *it) const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   182
      Array<T>* array = dereference();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   183
      log_trace(cds)("Iter(PrimitiveArray): %p [%d]", array, array->length());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   184
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   185
    virtual void metaspace_pointers_do_at(MetaspaceClosure *it, address new_loc) const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   186
      Array<T>* array = (Array<T>*)new_loc;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   187
      log_trace(cds)("Iter(PrimitiveArray): %p [%d]", array, array->length());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   188
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   189
  };
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   190
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   191
  // -------------------------------------------------- PointerArrayRef
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   192
  template <class T> class PointerArrayRef : public Ref {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   193
    Array<T*>** _mpp;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   194
    Array<T*>* dereference() const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   195
      return *_mpp;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   196
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   197
  protected:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   198
    virtual void** mpp() const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   199
      return (void**)_mpp;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   200
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   201
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   202
  public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   203
    PointerArrayRef(Array<T*>** mpp) : _mpp(mpp) {}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   204
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   205
    // all Arrays are read-only by default
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   206
    virtual bool is_read_only_by_default() const { return true; }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   207
    virtual bool not_null()                const { return dereference() != NULL; }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   208
    virtual int size()                     const { return dereference()->size(); }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   209
    virtual MetaspaceObj::Type msotype()   const { return MetaspaceObj::array_type(sizeof(T*)); }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   210
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   211
    virtual void metaspace_pointers_do(MetaspaceClosure *it) const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   212
      metaspace_pointers_do_at_impl(it, dereference());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   213
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   214
    virtual void metaspace_pointers_do_at(MetaspaceClosure *it, address new_loc) const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   215
      metaspace_pointers_do_at_impl(it, (Array<T*>*)new_loc);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   216
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   217
  private:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   218
    void metaspace_pointers_do_at_impl(MetaspaceClosure *it, Array<T*>* array) const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   219
      log_trace(cds)("Iter(ObjectArray): %p [%d]", array, array->length());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   220
      for (int i = 0; i < array->length(); i++) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   221
        T** mpp = array->adr_at(i);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   222
        it->push(mpp);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   223
      }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   224
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   225
  };
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   226
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   227
  void push_impl(Ref* ref, Writability w);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   228
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   229
public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   230
  // returns true if we want to keep iterating the pointers embedded inside <ref>
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   231
  virtual bool do_ref(Ref* ref, bool read_only) = 0;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   232
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   233
  // When you do:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   234
  //     void MyType::metaspace_pointers_do(MetaspaceClosure* it) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   235
  //       it->push(_my_field)
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   236
  //
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   237
  // C++ will try to match the "most specific" template function. This one will
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   238
  // will be matched if possible (if mpp is an Array<> of any pointer type).
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   239
  template <typename T> void push(Array<T*>** mpp, Writability w = _default) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   240
    PointerArrayRef<T> ref(mpp);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   241
    push_impl(&ref, w);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   242
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   243
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   244
  // If the above function doesn't match (mpp is an Array<>, but T is not a pointer type), then
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   245
  // this is the second choice.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   246
  template <typename T> void push(Array<T>** mpp, Writability w = _default) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   247
    PrimitiveArrayRef<T> ref(mpp);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   248
    push_impl(&ref, w);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   249
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   250
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   251
  // If the above function doesn't match (mpp is not an Array<> type), then
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   252
  // this will be matched by default.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   253
  template <class T> void push(T** mpp, Writability w = _default) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   254
    ObjectRef<T> ref(mpp);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   255
    push_impl(&ref, w);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   256
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   257
};
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   258
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   259
// This is a special MetaspaceClosure that visits each unique MetaspaceObj once.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   260
class UniqueMetaspaceClosure : public MetaspaceClosure {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   261
  // Do not override. Returns true if we are discovering ref->obj() for the first time.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   262
  virtual bool do_ref(Ref* ref, bool read_only);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   263
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   264
public:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   265
  // Gets called the first time we discover an object.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   266
  virtual void do_unique_ref(Ref* ref, bool read_only) = 0;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   267
private:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   268
  static unsigned my_hash(const address& a) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   269
    return primitive_hash<address>(a);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   270
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   271
  static bool my_equals(const address& a0, const address& a1) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   272
    return primitive_equals<address>(a0, a1);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   273
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   274
  ResourceHashtable<
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   275
      address, bool,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   276
      UniqueMetaspaceClosure::my_hash,   // solaris compiler doesn't like: primitive_hash<address>
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   277
      UniqueMetaspaceClosure::my_equals, // solaris compiler doesn't like: primitive_equals<address>
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
   278
      15889,                             // prime number
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 46746
diff changeset
   279
      ResourceObj::C_HEAP> _has_been_visited;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   280
};
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   281
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
   282
#endif // SHARE_VM_MEMORY_METASPACE_ITERATOR_HPP