hotspot/src/share/vm/prims/jvmtiGetLoadedClasses.cpp
author coleenp
Sat, 01 Sep 2012 13:25:18 -0400
changeset 13728 882756847a04
parent 13195 be27e1b6a4b9
child 14488 ab48109f7d1b
permissions -rw-r--r--
6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
     2
 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/universe.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "prims/jvmtiGetLoadedClasses.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "runtime/thread.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// The closure for GetLoadedClasses and GetClassLoaderClasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
class JvmtiGetLoadedClassesClosure : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  // Since the SystemDictionary::classes_do callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  // doesn't pass a closureData pointer,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  // we use a thread-local slot to hold a pointer to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  // a stack allocated instance of this structure.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  jobject _initiatingLoader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  int     _count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  Handle* _list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  int     _index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // Getting and setting the thread local pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  static JvmtiGetLoadedClassesClosure* get_this() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    JvmtiGetLoadedClassesClosure* result = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    JavaThread* thread = JavaThread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    result = thread->get_jvmti_get_loaded_classes_closure();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  static void set_this(JvmtiGetLoadedClassesClosure* that) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    JavaThread* thread = JavaThread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    thread->set_jvmti_get_loaded_classes_closure(that);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // Constructor/Destructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  JvmtiGetLoadedClassesClosure() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    JvmtiGetLoadedClassesClosure* that = get_this();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    assert(that == NULL, "JvmtiGetLoadedClassesClosure in use");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    _initiatingLoader = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    _count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    _list = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    _index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    set_this(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  JvmtiGetLoadedClassesClosure(jobject initiatingLoader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    JvmtiGetLoadedClassesClosure* that = get_this();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    assert(that == NULL, "JvmtiGetLoadedClassesClosure in use");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    _initiatingLoader = initiatingLoader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    _count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    _list = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    _index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    set_this(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  ~JvmtiGetLoadedClassesClosure() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    JvmtiGetLoadedClassesClosure* that = get_this();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    assert(that != NULL, "JvmtiGetLoadedClassesClosure not found");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    set_this(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    _initiatingLoader = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    _count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    if (_list != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
      FreeHeap(_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
      _list = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    _index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // Accessors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  jobject get_initiatingLoader() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    return _initiatingLoader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  int get_count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    return _count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  void set_count(int value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    _count = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  Handle* get_list() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    return _list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  void set_list(Handle* value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    _list = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  int get_index() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    return _index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  void set_index(int value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    _index = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  Handle get_element(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    if ((_list != NULL) && (index < _count)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      return _list[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      assert(false, "empty get_element");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      return Handle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  void set_element(int index, Handle value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    if ((_list != NULL) && (index < _count)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      _list[index] = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      assert(false, "bad set_element");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // Other predicates
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  bool available() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    return (_list != NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // For debugging.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  void check(int limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    for (int i = 0; i < limit; i += 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      assert(Universe::heap()->is_in(get_element(i)()), "check fails");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Public methods that get called within the scope of the closure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  void allocate() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   155
    _list = NEW_C_HEAP_ARRAY(Handle, _count, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    assert(_list != NULL, "Out of memory");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    if (_list == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      _count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  void extract(JvmtiEnv *env, jclass* result) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    for (int index = 0; index < _count; index += 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      result[index] = (jclass) env->jni_reference(get_element(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // Finally, the static methods that are the callbacks
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   169
  static void increment(Klass* k) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    if (that->get_initiatingLoader() == NULL) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   172
      for (Klass* l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
        that->set_count(that->get_count() + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    } else if (k != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      // if initiating loader not null, just include the instance with 1 dimension
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      that->set_count(that->get_count() + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   181
  static void increment_with_loader(Klass* k, ClassLoaderData* loader_data) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   183
    oop class_loader = loader_data->class_loader();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   184
    if (class_loader == JNIHandles::resolve(that->get_initiatingLoader())) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   185
      for (Klass* l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
        that->set_count(that->get_count() + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   191
  static void prim_array_increment_with_loader(Klass* array, ClassLoaderData* loader_data) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   193
    oop class_loader = loader_data->class_loader();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   194
    if (class_loader == JNIHandles::resolve(that->get_initiatingLoader())) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
      that->set_count(that->get_count() + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   199
  static void add(Klass* k) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    if (that->available()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      if (that->get_initiatingLoader() == NULL) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   203
        for (Klass* l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
          oop mirror = Klass::cast(l)->java_mirror();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
          that->set_element(that->get_index(), mirror);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
          that->set_index(that->get_index() + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
      } else if (k != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
        // if initiating loader not null, just include the instance with 1 dimension
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
        oop mirror = Klass::cast(k)->java_mirror();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
        that->set_element(that->get_index(), mirror);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
        that->set_index(that->get_index() + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   217
  static void add_with_loader(Klass* k, ClassLoaderData* loader_data) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    if (that->available()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   220
      oop class_loader = loader_data->class_loader();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   221
      if (class_loader == JNIHandles::resolve(that->get_initiatingLoader())) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   222
        for (Klass* l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
          oop mirror = Klass::cast(l)->java_mirror();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
          that->set_element(that->get_index(), mirror);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
          that->set_index(that->get_index() + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  // increment the count for the given basic type array class (and any
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // multi-dimensional arrays). For example, for [B we check for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  // [[B, [[[B, .. and the count is incremented for each one that exists.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   234
  static void increment_for_basic_type_arrays(Klass* k) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    assert(that != NULL, "no JvmtiGetLoadedClassesClosure");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   237
    for (Klass* l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      that->set_count(that->get_count() + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  // add the basic type array class and its multi-dimensional array classes to the list
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   243
  static void add_for_basic_type_arrays(Klass* k) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    JvmtiGetLoadedClassesClosure* that = JvmtiGetLoadedClassesClosure::get_this();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    assert(that != NULL, "no JvmtiGetLoadedClassesClosure");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    assert(that->available(), "no list");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   247
    for (Klass* l = k; l != NULL; l = Klass::cast(l)->array_klass_or_null()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
      oop mirror = Klass::cast(l)->java_mirror();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      that->set_element(that->get_index(), mirror);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      that->set_index(that->get_index() + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
jvmtiError
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
JvmtiGetLoadedClasses::getLoadedClasses(JvmtiEnv *env, jint* classCountPtr, jclass** classesPtr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  // Since SystemDictionary::classes_do only takes a function pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  // and doesn't call back with a closure data pointer,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  // we can only pass static methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  JvmtiGetLoadedClassesClosure closure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    // To get a consistent list of classes we need MultiArray_lock to ensure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    // array classes aren't created, and SystemDictionary_lock to ensure that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    // classes aren't added to the system dictionary,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    MutexLocker ma(MultiArray_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    MutexLocker sd(SystemDictionary_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    // First, count the classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    SystemDictionary::classes_do(&JvmtiGetLoadedClassesClosure::increment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    Universe::basic_type_classes_do(&JvmtiGetLoadedClassesClosure::increment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    // Next, fill in the classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    closure.allocate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    SystemDictionary::classes_do(&JvmtiGetLoadedClassesClosure::add);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    Universe::basic_type_classes_do(&JvmtiGetLoadedClassesClosure::add);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    // Drop the SystemDictionary_lock, so the results could be wrong from here,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    // but we still have a snapshot.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  // Post results
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  jclass* result_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  jvmtiError err = env->Allocate(closure.get_count() * sizeof(jclass),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
                                 (unsigned char**)&result_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  if (err != JVMTI_ERROR_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    return err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  closure.extract(env, result_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  *classCountPtr = closure.get_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  *classesPtr = result_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  return JVMTI_ERROR_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
jvmtiError
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
JvmtiGetLoadedClasses::getClassLoaderClasses(JvmtiEnv *env, jobject initiatingLoader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
                                             jint* classCountPtr, jclass** classesPtr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  // Since SystemDictionary::classes_do only takes a function pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  // and doesn't call back with a closure data pointer,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  // we can only pass static methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  JvmtiGetLoadedClassesClosure closure(initiatingLoader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    // To get a consistent list of classes we need MultiArray_lock to ensure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    // array classes aren't created, and SystemDictionary_lock to ensure that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    // classes aren't added to the system dictionary,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    MutexLocker ma(MultiArray_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    MutexLocker sd(SystemDictionary_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    // First, count the classes in the system dictionary which have this loader recorded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    // as an initiating loader. For basic type arrays this information is not recorded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    // so GetClassLoaderClasses will return all of the basic type arrays. This is okay
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    // because the defining loader for basic type arrays is always the boot class loader
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    // and these classes are "visible" to all loaders.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    SystemDictionary::classes_do(&JvmtiGetLoadedClassesClosure::increment_with_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    Universe::basic_type_classes_do(&JvmtiGetLoadedClassesClosure::increment_for_basic_type_arrays);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    // Next, fill in the classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    closure.allocate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    SystemDictionary::classes_do(&JvmtiGetLoadedClassesClosure::add_with_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    Universe::basic_type_classes_do(&JvmtiGetLoadedClassesClosure::add_for_basic_type_arrays);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    // Drop the SystemDictionary_lock, so the results could be wrong from here,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    // but we still have a snapshot.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  // Post results
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  jclass* result_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  jvmtiError err = env->Allocate(closure.get_count() * sizeof(jclass),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
                                 (unsigned char**)&result_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  if (err != JVMTI_ERROR_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    return err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  closure.extract(env, result_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  *classCountPtr = closure.get_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  *classesPtr = result_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  return JVMTI_ERROR_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
}