src/hotspot/share/prims/jvmtiTagMap.cpp
author lfoltan
Mon, 21 Oct 2019 13:13:16 -0400
changeset 58722 cba8afa5cfed
parent 58177 4932dce35882
child 59153 1152339c298a
permissions -rw-r--r--
8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently Summary: Increase the use of type signature constants instead of hard coded characters within the JVM. Reviewed-by: coleenp, dholmes, fparain Contributed-by: lois.foltan@oracle.com, john.r.rose@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
54376
2a2fab6fb3a5 8221732: Introduce CollectedHeap::hash_oop()
pliden
parents: 54121
diff changeset
     2
 * Copyright (c) 2003, 2019, 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: 4571
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
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: 4571
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"
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents: 51665
diff changeset
    26
#include "classfile/classLoaderDataGraph.hpp"
35498
392b50de06c6 8146401: Clean up oop.hpp: add inline directives and fix header files
goetz
parents: 33638
diff changeset
    27
#include "classfile/javaClasses.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "classfile/symbolTable.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "classfile/vmSymbols.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "jvmtifiles/jvmtiEnv.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49480
diff changeset
    32
#include "logging/log.hpp"
49360
886acec3b4c6 8199275: Fix inclusions of allocation.inline.hpp
stefank
parents: 49340
diff changeset
    33
#include "memory/allocation.inline.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 35498
diff changeset
    34
#include "memory/resourceArea.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54690
diff changeset
    35
#include "memory/universe.hpp"
48616
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
    36
#include "oops/access.inline.hpp"
49041
44122f767467 8198286: Direct memory accessors in typeArrayOop.hpp should use Access API
eosterlund
parents: 49036
diff changeset
    37
#include "oops/arrayOop.inline.hpp"
49340
4e82736053ae 8191102: Incorrect include file use in classLoader.hpp
hseigel
parents: 49192
diff changeset
    38
#include "oops/constantPool.inline.hpp"
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8076
diff changeset
    39
#include "oops/instanceMirrorKlass.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    40
#include "oops/objArrayKlass.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 28624
diff changeset
    41
#include "oops/objArrayOop.inline.hpp"
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 28624
diff changeset
    42
#include "oops/oop.inline.hpp"
49036
bc92debe57e4 8197999: Accessors in typeArrayOopDesc should use new Access API
rkennke
parents: 48787
diff changeset
    43
#include "oops/typeArrayOop.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    44
#include "prims/jvmtiEventController.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    45
#include "prims/jvmtiEventController.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    46
#include "prims/jvmtiExport.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    47
#include "prims/jvmtiImpl.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    48
#include "prims/jvmtiTagMap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    49
#include "runtime/biasedLocking.hpp"
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49476
diff changeset
    50
#include "runtime/frame.inline.hpp"
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49476
diff changeset
    51
#include "runtime/handles.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    52
#include "runtime/javaCalls.hpp"
49192
6734eeef4283 8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents: 49041
diff changeset
    53
#include "runtime/jniHandles.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    54
#include "runtime/mutex.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    55
#include "runtime/mutexLocker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    56
#include "runtime/reflectionUtils.hpp"
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47765
diff changeset
    57
#include "runtime/thread.inline.hpp"
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47765
diff changeset
    58
#include "runtime/threadSMR.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    59
#include "runtime/vframe.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    60
#include "runtime/vmThread.hpp"
52877
9e041366c764 8214850: Rename vm_operations.?pp files to vmOperations.?pp files
tschatzl
parents: 52652
diff changeset
    61
#include "runtime/vmOperations.hpp"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14488
diff changeset
    62
#include "utilities/macros.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50297
diff changeset
    63
#if INCLUDE_ZGC
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50297
diff changeset
    64
#include "gc/z/zGlobals.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents: 50297
diff changeset
    65
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
// JvmtiTagHashmapEntry
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
//
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
    69
// Each entry encapsulates a reference to the tagged object
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
// and the tag value. In addition an entry includes a next pointer which
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
// is used to chain entries together.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13096
diff changeset
    73
class JvmtiTagHashmapEntry : public CHeapObj<mtInternal> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  friend class JvmtiTagMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
    77
  oop _object;                          // tagged object
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  jlong _tag;                           // the tag
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  JvmtiTagHashmapEntry* _next;          // next on the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
    81
  inline void init(oop object, jlong tag) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    _object = object;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    _tag = tag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    _next = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // constructor
48616
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
    88
  JvmtiTagHashmapEntry(oop object, jlong tag) { init(object, tag); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // accessor methods
48616
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
    93
  inline oop* object_addr() { return &_object; }
50599
ecc2af326b5f 8204939: Change Access nomenclature: root to native
kbarrett
parents: 50525
diff changeset
    94
  inline oop object()       { return NativeAccess<ON_PHANTOM_OOP_REF>::oop_load(object_addr()); }
48616
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
    95
  // Peek at the object without keeping it alive. The returned object must be
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
    96
  // kept alive using a normal access if it leaks out of a thread transition from VM.
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
    97
  inline oop object_peek()  {
50599
ecc2af326b5f 8204939: Change Access nomenclature: root to native
kbarrett
parents: 50525
diff changeset
    98
    return NativeAccess<ON_PHANTOM_OOP_REF | AS_NO_KEEPALIVE>::oop_load(object_addr());
48616
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
    99
  }
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
   100
  inline jlong tag() const  { return _tag; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  inline void set_tag(jlong tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    assert(tag != 0, "can't be zero");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    _tag = tag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
48616
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
   107
  inline bool equals(oop object) {
58177
4932dce35882 8230841: Remove oopDesc::equals()
pliden
parents: 58015
diff changeset
   108
    return object == object_peek();
48616
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
   109
  }
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
   110
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
   111
  inline JvmtiTagHashmapEntry* next() const        { return _next; }
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
   112
  inline void set_next(JvmtiTagHashmapEntry* next) { _next = next; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// JvmtiTagHashmap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
// A hashmap is essentially a table of pointers to entries. Entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
// are hashed to a location, or position in the table, and then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// chained from that location. The "key" for hashing is address of
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   121
// the object, or oop. The "value" is the tag value.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
// A hashmap maintains a count of the number entries in the hashmap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// and resizes if the number of entries exceeds a given threshold.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
// The threshold is specified as a percentage of the size - for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
// example a threshold of 0.75 will trigger the hashmap to resize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// if the number of entries is >75% of table size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
// A hashmap provides functions for adding, removing, and finding
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
// entries. It also provides a function to iterate over all entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
// in the hashmap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13096
diff changeset
   133
class JvmtiTagHashmap : public CHeapObj<mtInternal> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  friend class JvmtiTagMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    small_trace_threshold  = 10000,                  // threshold for tracing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    medium_trace_threshold = 100000,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    large_trace_threshold  = 1000000,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    initial_trace_threshold = small_trace_threshold
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  static int _sizes[];                  // array of possible hashmap sizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  int _size;                            // actual size of the table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  int _size_index;                      // index into size table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  int _entry_count;                     // number of entries in the hashmap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  float _load_factor;                   // load factor as a % of the size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  int _resize_threshold;                // computed threshold to trigger resizing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  bool _resizing_enabled;               // indicates if hashmap can resize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  int _trace_threshold;                 // threshold for trace messages
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  JvmtiTagHashmapEntry** _table;        // the table of entries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // private accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  int resize_threshold() const                  { return _resize_threshold; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  int trace_threshold() const                   { return _trace_threshold; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  // initialize the hashmap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  void init(int size_index=0, float load_factor=4.0f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    int initial_size =  _sizes[size_index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    _size_index = size_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    _size = initial_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    _entry_count = 0;
37993
e446184da25e 8154059: JVMTI ObjectTagging to UL
rehn
parents: 37248
diff changeset
   168
    _trace_threshold = initial_trace_threshold;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    _load_factor = load_factor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    _resize_threshold = (int)(_load_factor * _size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    _resizing_enabled = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    size_t s = initial_size * sizeof(JvmtiTagHashmapEntry*);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13096
diff changeset
   173
    _table = (JvmtiTagHashmapEntry**)os::malloc(s, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    if (_table == NULL) {
17087
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 15482
diff changeset
   175
      vm_exit_out_of_memory(s, OOM_MALLOC_ERROR,
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 15482
diff changeset
   176
        "unable to allocate initial hashtable for jvmti object tags");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    for (int i=0; i<initial_size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      _table[i] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // hash a given key (oop) with the specified size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  static unsigned int hash(oop key, int size) {
54376
2a2fab6fb3a5 8221732: Introduce CollectedHeap::hash_oop()
pliden
parents: 54121
diff changeset
   185
    const oop obj = Access<>::resolve(key);
2a2fab6fb3a5 8221732: Introduce CollectedHeap::hash_oop()
pliden
parents: 54121
diff changeset
   186
    const unsigned int hash = Universe::heap()->hash_oop(obj);
2a2fab6fb3a5 8221732: Introduce CollectedHeap::hash_oop()
pliden
parents: 54121
diff changeset
   187
    return hash % size;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  // hash a given key (oop)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  unsigned int hash(oop key) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    return hash(key, _size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  // resize the hashmap - allocates a large table and re-hashes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  // all entries into the new table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  void resize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    int new_size_index = _size_index+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    int new_size = _sizes[new_size_index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    if (new_size < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      // hashmap already at maximum capacity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    // allocate new table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    size_t s = new_size * sizeof(JvmtiTagHashmapEntry*);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13096
diff changeset
   207
    JvmtiTagHashmapEntry** new_table = (JvmtiTagHashmapEntry**)os::malloc(s, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    if (new_table == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
      warning("unable to allocate larger hashtable for jvmti object tags");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
      set_resizing_enabled(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    // initialize new table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    for (i=0; i<new_size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
      new_table[i] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    // rehash all entries into the new table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    for (i=0; i<_size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      JvmtiTagHashmapEntry* entry = _table[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      while (entry != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
        JvmtiTagHashmapEntry* next = entry->next();
48616
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
   225
        oop key = entry->object_peek();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
        assert(key != NULL, "jni weak reference cleared!!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
        unsigned int h = hash(key, new_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
        JvmtiTagHashmapEntry* anchor = new_table[h];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
        if (anchor == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
          new_table[h] = entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
          entry->set_next(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
          entry->set_next(anchor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
          new_table[h] = entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
        entry = next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    // free old table and update settings.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    os::free((void*)_table);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    _table = new_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    _size_index = new_size_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    _size = new_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    // compute new resize threshold
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    _resize_threshold = (int)(_load_factor * _size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  // internal remove function - remove an entry at a given position in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  // table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  inline void remove(JvmtiTagHashmapEntry* prev, int pos, JvmtiTagHashmapEntry* entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    assert(pos >= 0 && pos < _size, "out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    if (prev == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
      _table[pos] = entry->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      prev->set_next(entry->next());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    assert(_entry_count > 0, "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    _entry_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // resizing switch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  bool is_resizing_enabled() const          { return _resizing_enabled; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  void set_resizing_enabled(bool enable)    { _resizing_enabled = enable; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  // debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  void print_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  void compute_next_trace_threshold();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  // create a JvmtiTagHashmap of a preferred size and optionally a load factor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  // The preferred size is rounded down to an actual size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  JvmtiTagHashmap(int size, float load_factor=0.0f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    int i=0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    while (_sizes[i] < size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
      if (_sizes[i] < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
        assert(i > 0, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
        i--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
      i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    // if a load factor is specified then use it, otherwise use default
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    if (load_factor > 0.01f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
      init(i, load_factor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      init(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  // create a JvmtiTagHashmap with default settings
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  JvmtiTagHashmap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  // release table when JvmtiTagHashmap destroyed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  ~JvmtiTagHashmap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    if (_table != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
      os::free((void*)_table);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
      _table = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  int size() const                              { return _size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  JvmtiTagHashmapEntry** table() const          { return _table; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  int entry_count() const                       { return _entry_count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  // find an entry in the hashmap, returns NULL if not found.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  inline JvmtiTagHashmapEntry* find(oop key) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    unsigned int h = hash(key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    JvmtiTagHashmapEntry* entry = _table[h];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    while (entry != NULL) {
48616
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
   318
      if (entry->equals(key)) {
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   319
         return entry;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
      entry = entry->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    }
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   323
    return NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  // add a new entry to hashmap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  inline void add(oop key, JvmtiTagHashmapEntry* entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    assert(key != NULL, "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    assert(find(key) == NULL, "duplicate detected");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    unsigned int h = hash(key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    JvmtiTagHashmapEntry* anchor = _table[h];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    if (anchor == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      _table[h] = entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
      entry->set_next(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
      entry->set_next(anchor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
      _table[h] = entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    _entry_count++;
37993
e446184da25e 8154059: JVMTI ObjectTagging to UL
rehn
parents: 37248
diff changeset
   342
    if (log_is_enabled(Debug, jvmti, objecttagging) && entry_count() >= trace_threshold()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
      print_memory_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
      compute_next_trace_threshold();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    // if the number of entries exceed the threshold then resize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    if (entry_count() > resize_threshold() && is_resizing_enabled()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
      resize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  // remove an entry with the given key.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  inline JvmtiTagHashmapEntry* remove(oop key) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    unsigned int h = hash(key);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    JvmtiTagHashmapEntry* entry = _table[h];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    JvmtiTagHashmapEntry* prev = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    while (entry != NULL) {
48616
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
   359
      if (entry->equals(key)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      prev = entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
      entry = entry->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    if (entry != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
      remove(prev, h, entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  // iterate over all entries in the hashmap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  void entry_iterate(JvmtiTagHashmapEntryClosure* closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
// possible hashmap sizes - odd primes that roughly double in size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
// To avoid excessive resizing the odd primes from 4801-76831 and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
// 76831-307261 have been removed. The list must be terminated by -1.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
int JvmtiTagHashmap::_sizes[] =  { 4801, 76831, 307261, 614563, 1228891,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    2457733, 4915219, 9830479, 19660831, 39321619, 78643219, -1 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
// A supporting class for iterating over all entries in Hashmap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
class JvmtiTagHashmapEntryClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  virtual void do_entry(JvmtiTagHashmapEntry* entry) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
// iterate over all entries in the hashmap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
void JvmtiTagHashmap::entry_iterate(JvmtiTagHashmapEntryClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  for (int i=0; i<_size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    JvmtiTagHashmapEntry* entry = _table[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    JvmtiTagHashmapEntry* prev = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    while (entry != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
      // obtain the next entry before invoking do_entry - this is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
      // necessary because do_entry may remove the entry from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
      // hashmap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
      JvmtiTagHashmapEntry* next = entry->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
      closure->do_entry(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
      entry = next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
// debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
void JvmtiTagHashmap::print_memory_usage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  intptr_t p = (intptr_t)this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  tty->print("[JvmtiTagHashmap @ " INTPTR_FORMAT, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  // table + entries in KB
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  int hashmap_usage = (size()*sizeof(JvmtiTagHashmapEntry*) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    entry_count()*sizeof(JvmtiTagHashmapEntry))/K;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  int weak_globals_usage = (int)(JNIHandles::weak_global_handle_memory_usage()/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  tty->print_cr(", %d entries (%d KB) <JNI weak globals: %d KB>]",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    entry_count(), hashmap_usage, weak_globals_usage);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
// compute threshold for the next trace message
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
void JvmtiTagHashmap::compute_next_trace_threshold() {
37993
e446184da25e 8154059: JVMTI ObjectTagging to UL
rehn
parents: 37248
diff changeset
   421
  _trace_threshold = entry_count();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  if (trace_threshold() < medium_trace_threshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    _trace_threshold += small_trace_threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    if (trace_threshold() < large_trace_threshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
      _trace_threshold += medium_trace_threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
      _trace_threshold += large_trace_threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
// create a JvmtiTagMap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
JvmtiTagMap::JvmtiTagMap(JvmtiEnv* env) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  _env(env),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  _lock(Mutex::nonleaf+2, "JvmtiTagMap._lock", false),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  _free_entries(NULL),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  _free_entries_count(0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  assert(JvmtiThreadState_lock->is_locked(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  assert(((JvmtiEnvBase *)env)->tag_map() == NULL, "tag map already exists for environment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   443
  _hashmap = new JvmtiTagHashmap();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  // finally add us to the environment
54674
27c8a2e0b0e5 8223177: Data race on JvmtiEnvBase::_tag_map in double-checked locking
manc
parents: 54669
diff changeset
   446
  ((JvmtiEnvBase *)env)->release_set_tag_map(this);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
// destroy a JvmtiTagMap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
JvmtiTagMap::~JvmtiTagMap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  // no lock acquired as we assume the enclosing environment is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  // also being destroryed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  ((JvmtiEnvBase *)_env)->set_tag_map(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   457
  JvmtiTagHashmapEntry** table = _hashmap->table();
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   458
  for (int j = 0; j < _hashmap->size(); j++) {
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   459
    JvmtiTagHashmapEntry* entry = table[j];
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   460
    while (entry != NULL) {
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   461
      JvmtiTagHashmapEntry* next = entry->next();
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   462
      delete entry;
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   463
      entry = next;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   467
  // finally destroy the hashmap
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   468
  delete _hashmap;
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   469
  _hashmap = NULL;
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   470
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  // remove any entries on the free list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  JvmtiTagHashmapEntry* entry = _free_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  while (entry != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    JvmtiTagHashmapEntry* next = entry->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    delete entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    entry = next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  }
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   478
  _free_entries = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
// create a hashmap entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
// - if there's an entry on the (per-environment) free list then this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
// is returned. Otherwise an new entry is allocated.
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   484
JvmtiTagHashmapEntry* JvmtiTagMap::create_entry(oop ref, jlong tag) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  assert(Thread::current()->is_VM_thread() || is_locked(), "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  JvmtiTagHashmapEntry* entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  if (_free_entries == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    entry = new JvmtiTagHashmapEntry(ref, tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    assert(_free_entries_count > 0, "mismatched _free_entries_count");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    _free_entries_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    entry = _free_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
    _free_entries = entry->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    entry->init(ref, tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
// destroy an entry by returning it to the free list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
void JvmtiTagMap::destroy_entry(JvmtiTagHashmapEntry* entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  assert(SafepointSynchronize::is_at_safepoint() || is_locked(), "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  // limit the size of the free list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  if (_free_entries_count >= max_free_entries) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    delete entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
    entry->set_next(_free_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
    _free_entries = entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    _free_entries_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
// returns the tag map for the given environments. If the tag map
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
// doesn't exist then it is created.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
JvmtiTagMap* JvmtiTagMap::tag_map_for(JvmtiEnv* env) {
54690
7ab4310ed472 8223227: Rename acquire_tag_map() to tag_map_acquire() in jvmtiEnvBase
manc
parents: 54674
diff changeset
   515
  JvmtiTagMap* tag_map = ((JvmtiEnvBase*)env)->tag_map_acquire();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  if (tag_map == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    MutexLocker mu(JvmtiThreadState_lock);
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   518
    tag_map = ((JvmtiEnvBase*)env)->tag_map();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
    if (tag_map == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
      tag_map = new JvmtiTagMap(env);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  } else {
57745
789e967c2731 5103339: Strengthen NoSafepointVerifier
coleenp
parents: 55740
diff changeset
   523
    DEBUG_ONLY(Thread::current()->check_possible_safepoint());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  return tag_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
// iterate over all entries in the tag map.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
void JvmtiTagMap::entry_iterate(JvmtiTagHashmapEntryClosure* closure) {
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   530
  hashmap()->entry_iterate(closure);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
// returns true if the hashmaps are empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
bool JvmtiTagMap::is_empty() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  assert(SafepointSynchronize::is_at_safepoint() || is_locked(), "checking");
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   536
  return hashmap()->entry_count() == 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
// Return the tag value for an object, or 0 if the object is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
// not tagged
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
static inline jlong tag_for(JvmtiTagMap* tag_map, oop o) {
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   544
  JvmtiTagHashmapEntry* entry = tag_map->hashmap()->find(o);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  if (entry == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    return entry->tag();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
// A CallbackWrapper is a support class for querying and tagging an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
// around a callback to a profiler. The constructor does pre-callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
// work to get the tag value, klass tag value, ... and the destructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
// does the post-callback work of tagging or untagging the object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
// {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
//   CallbackWrapper wrapper(tag_map, o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
//   (*callback)(wrapper.klass_tag(), wrapper.obj_size(), wrapper.obj_tag_p(), ...)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
// } // wrapper goes out of scope here which results in the destructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
//      checking to see if the object has been tagged, untagged, or the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
//      tag value has changed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
class CallbackWrapper : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  JvmtiTagMap* _tag_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  JvmtiTagHashmap* _hashmap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  JvmtiTagHashmapEntry* _entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  oop _o;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  jlong _obj_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  jlong _obj_tag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  jlong _klass_tag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  JvmtiTagMap* tag_map() const      { return _tag_map; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  // invoked post-callback to tag, untag, or update the tag of an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  void inline post_callback_tag_update(oop o, JvmtiTagHashmap* hashmap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
                                       JvmtiTagHashmapEntry* entry, jlong obj_tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  CallbackWrapper(JvmtiTagMap* tag_map, oop o) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
    assert(Thread::current()->is_VM_thread() || tag_map->is_locked(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
           "MT unsafe or must be VM thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   588
    // object to tag
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   589
    _o = o;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    // object size
13096
8a01a0702816 7178846: IterateThroughHeap: heap_iteration_callback passes a negative size
sla
parents: 11773
diff changeset
   592
    _obj_size = (jlong)_o->size() * wordSize;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
    // record the context
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
    _tag_map = tag_map;
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   596
    _hashmap = tag_map->hashmap();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
    _entry = _hashmap->find(_o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
    // get object tag
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
    _obj_tag = (_entry == NULL) ? 0 : _entry->tag();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    // get the class and the class's tag value
33602
16053580a684 8139163: InstanceKlass::cast passes through NULL
coleenp
parents: 33151
diff changeset
   603
    assert(SystemDictionary::Class_klass()->is_mirror_instance_klass(), "Is not?");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   604
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   605
    _klass_tag = tag_for(tag_map, _o->klass()->java_mirror());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  ~CallbackWrapper() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    post_callback_tag_update(_o, _hashmap, _entry, _obj_tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  inline jlong* obj_tag_p()                     { return &_obj_tag; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  inline jlong obj_size() const                 { return _obj_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  inline jlong obj_tag() const                  { return _obj_tag; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  inline jlong klass_tag() const                { return _klass_tag; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
// callback post-callback to tag, untag, or update the tag of an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
void inline CallbackWrapper::post_callback_tag_update(oop o,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
                                                      JvmtiTagHashmap* hashmap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
                                                      JvmtiTagHashmapEntry* entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
                                                      jlong obj_tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  if (entry == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
    if (obj_tag != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
      // callback has tagged the object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
      assert(Thread::current()->is_VM_thread(), "must be VMThread");
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   629
      entry = tag_map()->create_entry(o, obj_tag);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
      hashmap->add(o, entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
    // object was previously tagged - the callback may have untagged
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
    // the object or changed the tag value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
    if (obj_tag == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
      JvmtiTagHashmapEntry* entry_removed = hashmap->remove(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
      assert(entry_removed == entry, "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
      tag_map()->destroy_entry(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
      if (obj_tag != entry->tag()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
         entry->set_tag(obj_tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
// An extended CallbackWrapper used when reporting an object reference
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
// to the agent.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
// {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
//   TwoOopCallbackWrapper wrapper(tag_map, referrer, o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
//   (*callback)(wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
//               wrapper.obj_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
//               wrapper.obj_tag_p()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
//               wrapper.referrer_tag_p(), ...)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
// } // wrapper goes out of scope here which results in the destructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
//      checking to see if the referrer object has been tagged, untagged,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
//      or the tag value has changed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
class TwoOopCallbackWrapper : public CallbackWrapper {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  bool _is_reference_to_self;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
  JvmtiTagHashmap* _referrer_hashmap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  JvmtiTagHashmapEntry* _referrer_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  oop _referrer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  jlong _referrer_obj_tag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  jlong _referrer_klass_tag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
  jlong* _referrer_tag_p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
  bool is_reference_to_self() const             { return _is_reference_to_self; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  TwoOopCallbackWrapper(JvmtiTagMap* tag_map, oop referrer, oop o) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
    CallbackWrapper(tag_map, o)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
    // self reference needs to be handled in a special way
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
    _is_reference_to_self = (referrer == o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
    if (_is_reference_to_self) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
      _referrer_klass_tag = klass_tag();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
      _referrer_tag_p = obj_tag_p();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    } else {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   687
      _referrer = referrer;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
      // record the context
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   689
      _referrer_hashmap = tag_map->hashmap();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
      _referrer_entry = _referrer_hashmap->find(_referrer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
      // get object tag
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
      _referrer_obj_tag = (_referrer_entry == NULL) ? 0 : _referrer_entry->tag();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
      _referrer_tag_p = &_referrer_obj_tag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
      // get referrer class tag.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   697
      _referrer_klass_tag = tag_for(tag_map, _referrer->klass()->java_mirror());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  ~TwoOopCallbackWrapper() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
    if (!is_reference_to_self()){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
      post_callback_tag_update(_referrer,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
                               _referrer_hashmap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
                               _referrer_entry,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
                               _referrer_obj_tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
  // address of referrer tag
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  // (for a self reference this will return the same thing as obj_tag_p())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
  inline jlong* referrer_tag_p()        { return _referrer_tag_p; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
  // referrer's class tag
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  inline jlong referrer_klass_tag()     { return _referrer_klass_tag; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
// tag an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
// This function is performance critical. If many threads attempt to tag objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
// around the same time then it's possible that the Mutex associated with the
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   722
// tag map will be a hot lock.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
void JvmtiTagMap::set_tag(jobject object, jlong tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
  MutexLocker ml(lock());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
  // resolve the object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
  oop o = JNIHandles::resolve_non_null(object);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
  // see if the object is already tagged
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   730
  JvmtiTagHashmap* hashmap = _hashmap;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
  JvmtiTagHashmapEntry* entry = hashmap->find(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  // if the object is not already tagged then we tag it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
  if (entry == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
    if (tag != 0) {
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   736
      entry = create_entry(o, tag);
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
   737
      hashmap->add(o, entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
      // no-op
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
    // if the object is already tagged then we either update
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
    // the tag (if a new tag value has been provided)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
    // or remove the object if the new tag value is 0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
    if (tag == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
      hashmap->remove(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
      destroy_entry(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
      entry->set_tag(tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
// get the tag for an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
jlong JvmtiTagMap::get_tag(jobject object) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
  MutexLocker ml(lock());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  // resolve the object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  oop o = JNIHandles::resolve_non_null(object);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   761
  return tag_for(this, o);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
// Helper class used to describe the static or instance fields of a class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
// For each field it holds the field index (as defined by the JVMTI specification),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
// the field type, and the offset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13096
diff changeset
   769
class ClassFieldDescriptor: public CHeapObj<mtInternal> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
  int _field_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
  int _field_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  char _field_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
  ClassFieldDescriptor(int index, char type, int offset) :
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 51329
diff changeset
   776
    _field_index(index), _field_offset(offset), _field_type(type) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
  int field_index()  const  { return _field_index; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  char field_type()  const  { return _field_type; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  int field_offset() const  { return _field_offset; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13096
diff changeset
   783
class ClassFieldMap: public CHeapObj<mtInternal> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
    initial_field_count = 5
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
  // list of field descriptors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  GrowableArray<ClassFieldDescriptor*>* _fields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
  // constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
  ClassFieldMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
  // add a field
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
  void add(int index, char type, int offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
  // returns the field count for the given class
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
   799
  static int compute_field_count(InstanceKlass* ik);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
  ~ClassFieldMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  // access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  int field_count()                     { return _fields->length(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  ClassFieldDescriptor* field_at(int i) { return _fields->at(i); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
  // functions to create maps of static or instance fields
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   809
  static ClassFieldMap* create_map_of_static_fields(Klass* k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  static ClassFieldMap* create_map_of_instance_fields(oop obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
ClassFieldMap::ClassFieldMap() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13096
diff changeset
   814
  _fields = new (ResourceObj::C_HEAP, mtInternal)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13096
diff changeset
   815
    GrowableArray<ClassFieldDescriptor*>(initial_field_count, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
ClassFieldMap::~ClassFieldMap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
  for (int i=0; i<_fields->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
    delete _fields->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
  delete _fields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
void ClassFieldMap::add(int index, char type, int offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
  ClassFieldDescriptor* field = new ClassFieldDescriptor(index, type, offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  _fields->append(field);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
// Returns a heap allocated ClassFieldMap to describe the static fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
// of the given class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
//
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   833
ClassFieldMap* ClassFieldMap::create_map_of_static_fields(Klass* k) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
  HandleMark hm;
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
   835
  InstanceKlass* ik = InstanceKlass::cast(k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
  // create the field map
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
  ClassFieldMap* field_map = new ClassFieldMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
   840
  FilteredFieldStream f(ik, false, false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
  int max_field_index = f.field_count()-1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
  int index = 0;
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
   844
  for (FilteredFieldStream fld(ik, true, true); !fld.eos(); fld.next(), index++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
    // ignore instance fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
    if (!fld.access_flags().is_static()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
    }
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 51959
diff changeset
   849
    field_map->add(max_field_index - index, fld.signature()->char_at(0), fld.offset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
  return field_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
// Returns a heap allocated ClassFieldMap to describe the instance fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
// of the given class. All instance fields are included (this means public
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
// and private fields declared in superclasses and superinterfaces too).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
ClassFieldMap* ClassFieldMap::create_map_of_instance_fields(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
  HandleMark hm;
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
   860
  InstanceKlass* ik = InstanceKlass::cast(obj->klass());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
  // create the field map
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
  ClassFieldMap* field_map = new ClassFieldMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
   865
  FilteredFieldStream f(ik, false, false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
  int max_field_index = f.field_count()-1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
  int index = 0;
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
   870
  for (FilteredFieldStream fld(ik, false, false); !fld.eos(); fld.next(), index++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
    // ignore static fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
    if (fld.access_flags().is_static()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
    }
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 51959
diff changeset
   875
    field_map->add(max_field_index - index, fld.signature()->char_at(0), fld.offset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  return field_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
// Helper class used to cache a ClassFileMap for the instance fields of
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   882
// a cache. A JvmtiCachedClassFieldMap can be cached by an InstanceKlass during
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
// heap iteration and avoid creating a field map for each object in the heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
// (only need to create the map when the first instance of a class is encountered).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
//
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13096
diff changeset
   886
class JvmtiCachedClassFieldMap : public CHeapObj<mtInternal> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
   enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
     initial_class_count = 200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
   };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
  ClassFieldMap* _field_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
  ClassFieldMap* field_map() const          { return _field_map; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
  JvmtiCachedClassFieldMap(ClassFieldMap* field_map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
  ~JvmtiCachedClassFieldMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   898
  static GrowableArray<InstanceKlass*>* _class_list;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   899
  static void add_to_class_list(InstanceKlass* ik);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  // returns the field map for a given object (returning map cached
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   903
  // by InstanceKlass if possible
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  static ClassFieldMap* get_map_of_instance_fields(oop obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
  // removes the field map from all instanceKlasses - should be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  // called before VM operation completes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
  static void clear_cache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
  // returns the number of ClassFieldMap cached by instanceKlasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
  static int cached_field_map_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   914
GrowableArray<InstanceKlass*>* JvmtiCachedClassFieldMap::_class_list;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
JvmtiCachedClassFieldMap::JvmtiCachedClassFieldMap(ClassFieldMap* field_map) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
  _field_map = field_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
JvmtiCachedClassFieldMap::~JvmtiCachedClassFieldMap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
  if (_field_map != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
    delete _field_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
// Marker class to ensure that the class file map cache is only used in a defined
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
// scope.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
class ClassFieldMapCacheMark : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
   static bool _is_active;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
   ClassFieldMapCacheMark() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
     assert(Thread::current()->is_VM_thread(), "must be VMThread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
     assert(JvmtiCachedClassFieldMap::cached_field_map_count() == 0, "cache not empty");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
     assert(!_is_active, "ClassFieldMapCacheMark cannot be nested");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
     _is_active = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
   ~ClassFieldMapCacheMark() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
     JvmtiCachedClassFieldMap::clear_cache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
     _is_active = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
   static bool is_active() { return _is_active; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
bool ClassFieldMapCacheMark::_is_active;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   948
// record that the given InstanceKlass is caching a field map
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   949
void JvmtiCachedClassFieldMap::add_to_class_list(InstanceKlass* ik) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
  if (_class_list == NULL) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13096
diff changeset
   951
    _class_list = new (ResourceObj::C_HEAP, mtInternal)
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   952
      GrowableArray<InstanceKlass*>(initial_class_count, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
  _class_list->push(ik);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
// returns the instance field map for the given object
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   958
// (returns field map cached by the InstanceKlass if possible)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
ClassFieldMap* JvmtiCachedClassFieldMap::get_map_of_instance_fields(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
  assert(Thread::current()->is_VM_thread(), "must be VMThread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
  assert(ClassFieldMapCacheMark::is_active(), "ClassFieldMapCacheMark not active");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   963
  Klass* k = obj->klass();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   964
  InstanceKlass* ik = InstanceKlass::cast(k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
  // return cached map if possible
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  JvmtiCachedClassFieldMap* cached_map = ik->jvmti_cached_class_field_map();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  if (cached_map != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
    assert(cached_map->field_map() != NULL, "missing field list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
    return cached_map->field_map();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
    ClassFieldMap* field_map = ClassFieldMap::create_map_of_instance_fields(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
    cached_map = new JvmtiCachedClassFieldMap(field_map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
    ik->set_jvmti_cached_class_field_map(cached_map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
    add_to_class_list(ik);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
    return field_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
// remove the fields maps cached from all instanceKlasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
void JvmtiCachedClassFieldMap::clear_cache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  assert(Thread::current()->is_VM_thread(), "must be VMThread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
  if (_class_list != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
    for (int i = 0; i < _class_list->length(); i++) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   985
      InstanceKlass* ik = _class_list->at(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
      JvmtiCachedClassFieldMap* cached_map = ik->jvmti_cached_class_field_map();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
      assert(cached_map != NULL, "should not be NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
      ik->set_jvmti_cached_class_field_map(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
      delete cached_map;  // deletes the encapsulated field map
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
    delete _class_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
    _class_list = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
// returns the number of ClassFieldMap cached by instanceKlasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
int JvmtiCachedClassFieldMap::cached_field_map_count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
  return (_class_list == NULL) ? 0 : _class_list->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
// helper function to indicate if an object is filtered by its tag or class tag
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
static inline bool is_filtered_by_heap_filter(jlong obj_tag,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
                                              jlong klass_tag,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
                                              int heap_filter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
  // apply the heap filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
  if (obj_tag != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
    // filter out tagged objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
    if (heap_filter & JVMTI_HEAP_FILTER_TAGGED) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
    // filter out untagged objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
    if (heap_filter & JVMTI_HEAP_FILTER_UNTAGGED) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
  if (klass_tag != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
    // filter out objects with tagged classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
    if (heap_filter & JVMTI_HEAP_FILTER_CLASS_TAGGED) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
    // filter out objects with untagged classes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
    if (heap_filter & JVMTI_HEAP_FILTER_CLASS_UNTAGGED) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
// helper function to indicate if an object is filtered by a klass filter
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  1024
static inline bool is_filtered_by_klass_filter(oop obj, Klass* klass_filter) {
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  1025
  if (klass_filter != NULL) {
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  1026
    if (obj->klass() != klass_filter) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
// helper function to tell if a field is a primitive field or not
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
static inline bool is_primitive_field_type(char type) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58177
diff changeset
  1035
  return (type != JVM_SIGNATURE_CLASS && type != JVM_SIGNATURE_ARRAY);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
// helper function to copy the value from location addr to jvalue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
static inline void copy_to_jvalue(jvalue *v, address addr, jvmtiPrimitiveType value_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
  switch (value_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
    case JVMTI_PRIMITIVE_TYPE_BOOLEAN : { v->z = *(jboolean*)addr; break; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
    case JVMTI_PRIMITIVE_TYPE_BYTE    : { v->b = *(jbyte*)addr;    break; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
    case JVMTI_PRIMITIVE_TYPE_CHAR    : { v->c = *(jchar*)addr;    break; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
    case JVMTI_PRIMITIVE_TYPE_SHORT   : { v->s = *(jshort*)addr;   break; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
    case JVMTI_PRIMITIVE_TYPE_INT     : { v->i = *(jint*)addr;     break; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
    case JVMTI_PRIMITIVE_TYPE_LONG    : { v->j = *(jlong*)addr;    break; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
    case JVMTI_PRIMITIVE_TYPE_FLOAT   : { v->f = *(jfloat*)addr;   break; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
    case JVMTI_PRIMITIVE_TYPE_DOUBLE  : { v->d = *(jdouble*)addr;  break; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
    default: ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
// helper function to invoke string primitive value callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
// returns visit control flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
static jint invoke_string_value_callback(jvmtiStringPrimitiveValueCallback cb,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
                                         CallbackWrapper* wrapper,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
                                         oop str,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
                                         void* user_data)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
{
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 3908
diff changeset
  1060
  assert(str->klass() == SystemDictionary::String_klass(), "not a string");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
28624
88972fd01f71 6584008: jvmtiStringPrimitiveCallback should not be invoked when string value is null
aph
parents: 25716
diff changeset
  1062
  typeArrayOop s_value = java_lang_String::value(str);
88972fd01f71 6584008: jvmtiStringPrimitiveCallback should not be invoked when string value is null
aph
parents: 25716
diff changeset
  1063
88972fd01f71 6584008: jvmtiStringPrimitiveCallback should not be invoked when string value is null
aph
parents: 25716
diff changeset
  1064
  // JDK-6584008: the value field may be null if a String instance is
88972fd01f71 6584008: jvmtiStringPrimitiveCallback should not be invoked when string value is null
aph
parents: 25716
diff changeset
  1065
  // partially constructed.
88972fd01f71 6584008: jvmtiStringPrimitiveCallback should not be invoked when string value is null
aph
parents: 25716
diff changeset
  1066
  if (s_value == NULL) {
88972fd01f71 6584008: jvmtiStringPrimitiveCallback should not be invoked when string value is null
aph
parents: 25716
diff changeset
  1067
    return 0;
88972fd01f71 6584008: jvmtiStringPrimitiveCallback should not be invoked when string value is null
aph
parents: 25716
diff changeset
  1068
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
  // get the string value and length
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
  // (string value may be offset from the base)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
  int s_len = java_lang_String::length(str);
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1072
  bool is_latin1 = java_lang_String::is_latin1(str);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
  jchar* value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
  if (s_len > 0) {
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1075
    if (!is_latin1) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1076
      value = s_value->char_at_addr(0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1077
    } else {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1078
      // Inflate latin1 encoded string to UTF16
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1079
      jchar* buf = NEW_C_HEAP_ARRAY(jchar, s_len, mtInternal);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1080
      for (int i = 0; i < s_len; i++) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1081
        buf[i] = ((jchar) s_value->byte_at(i)) & 0xff;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1082
      }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1083
      value = &buf[0];
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1084
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
  } else {
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1086
    // Don't use char_at_addr(0) if length is 0
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
    value = (jchar*) s_value->base(T_CHAR);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
  // invoke the callback
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1091
  jint res = (*cb)(wrapper->klass_tag(),
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1092
                   wrapper->obj_size(),
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1093
                   wrapper->obj_tag_p(),
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1094
                   value,
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1095
                   (jint)s_len,
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1096
                   user_data);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1097
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1098
  if (is_latin1 && s_len > 0) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1099
    FREE_C_HEAP_ARRAY(jchar, value);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1100
  }
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33151
diff changeset
  1101
  return res;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
// helper function to invoke string primitive value callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
// returns visit control flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
static jint invoke_array_primitive_value_callback(jvmtiArrayPrimitiveValueCallback cb,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
                                                  CallbackWrapper* wrapper,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
                                                  oop obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
                                                  void* user_data)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
  assert(obj->is_typeArray(), "not a primitive array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
  // get base address of first element
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
  typeArrayOop array = typeArrayOop(obj);
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13741
diff changeset
  1115
  BasicType type = TypeArrayKlass::cast(array->klass())->element_type();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
  void* elements = array->base(type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
  // jvmtiPrimitiveType is defined so this mapping is always correct
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
  jvmtiPrimitiveType elem_type = (jvmtiPrimitiveType)type2char(type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
  return (*cb)(wrapper->klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
               wrapper->obj_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
               wrapper->obj_tag_p(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
               (jint)array->length(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
               elem_type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
               elements,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
               user_data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
// helper function to invoke the primitive field callback for all static fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
// of a given class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
static jint invoke_primitive_field_callback_for_static_fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
  (CallbackWrapper* wrapper,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
   oop obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
   jvmtiPrimitiveFieldCallback cb,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
   void* user_data)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
  // for static fields only the index will be set
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
  static jvmtiHeapReferenceInfo reference_info = { 0 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 3908
diff changeset
  1141
  assert(obj->klass() == SystemDictionary::Class_klass(), "not a class");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
  if (java_lang_Class::is_primitive(obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1145
  Klass* klass = java_lang_Class::as_Klass(obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
  // ignore classes for object and type arrays
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
  1148
  if (!klass->is_instance_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
  // ignore classes which aren't linked yet
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1153
  InstanceKlass* ik = InstanceKlass::cast(klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
  if (!ik->is_linked()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
  // get the field map
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1159
  ClassFieldMap* field_map = ClassFieldMap::create_map_of_static_fields(klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
  // invoke the callback for each static primitive field
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
  for (int i=0; i<field_map->field_count(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
    ClassFieldDescriptor* field = field_map->field_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
    // ignore non-primitive fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
    char type = field->field_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
    if (!is_primitive_field_type(type)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
    // one-to-one mapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
    jvmtiPrimitiveType value_type = (jvmtiPrimitiveType)type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
    // get offset and field value
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
    int offset = field->field_offset();
14082
7425bbf64ead 7093328: JVMTI: jvmtiPrimitiveFieldCallback always report 0's for static primitives
rbackman
parents: 13977
diff changeset
  1175
    address addr = (address)klass->java_mirror() + offset;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
    jvalue value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
    copy_to_jvalue(&value, addr, value_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
    // field index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
    reference_info.field.index = field->field_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
    // invoke the callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
    jint res = (*cb)(JVMTI_HEAP_REFERENCE_STATIC_FIELD,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
                     &reference_info,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
                     wrapper->klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
                     wrapper->obj_tag_p(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
                     value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
                     value_type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
                     user_data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
    if (res & JVMTI_VISIT_ABORT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
      delete field_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
      return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
  delete field_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
// helper function to invoke the primitive field callback for all instance fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
// of a given object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
static jint invoke_primitive_field_callback_for_instance_fields(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
  CallbackWrapper* wrapper,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
  oop obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
  jvmtiPrimitiveFieldCallback cb,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
  void* user_data)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
  // for instance fields only the index will be set
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
  static jvmtiHeapReferenceInfo reference_info = { 0 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
  // get the map of the instance fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
  ClassFieldMap* fields = JvmtiCachedClassFieldMap::get_map_of_instance_fields(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
  // invoke the callback for each instance primitive field
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
  for (int i=0; i<fields->field_count(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
    ClassFieldDescriptor* field = fields->field_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
    // ignore non-primitive fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
    char type = field->field_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
    if (!is_primitive_field_type(type)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
    // one-to-one mapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
    jvmtiPrimitiveType value_type = (jvmtiPrimitiveType)type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
    // get offset and field value
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
    int offset = field->field_offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
    address addr = (address)obj + offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
    jvalue value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
    copy_to_jvalue(&value, addr, value_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
    // field index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
    reference_info.field.index = field->field_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
    // invoke the callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
    jint res = (*cb)(JVMTI_HEAP_REFERENCE_FIELD,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
                     &reference_info,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
                     wrapper->klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
                     wrapper->obj_tag_p(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
                     value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
                     value_type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
                     user_data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
    if (res & JVMTI_VISIT_ABORT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
      return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
// VM operation to iterate over all objects in the heap (both reachable
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
// and unreachable)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
class VM_HeapIterateOperation: public VM_Operation {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
  ObjectClosure* _blk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
  VM_HeapIterateOperation(ObjectClosure* blk) { _blk = blk; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
  VMOp_Type type() const { return VMOp_HeapIterateOperation; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
  void doit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
    // allows class files maps to be cached during iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
    ClassFieldMapCacheMark cm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
    // make sure that heap is parsable (fills TLABs with filler objects)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
    Universe::heap()->ensure_parsability(false);  // no need to retire TLABs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
    // Verify heap before iteration - if the heap gets corrupted then
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
    // JVMTI's IterateOverHeap will crash.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
    if (VerifyBeforeIteration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
      Universe::verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
    // do the iteration
1893
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 1388
diff changeset
  1274
    // If this operation encounters a bad object when using CMS,
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 1388
diff changeset
  1275
    // consider using safe_object_iterate() which avoids perm gen
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 1388
diff changeset
  1276
    // objects that may contain bad references.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
    Universe::heap()->object_iterate(_blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
// An ObjectClosure used to support the deprecated IterateOverHeap and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
// IterateOverInstancesOfClass functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
class IterateOverHeapObjectClosure: public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
  JvmtiTagMap* _tag_map;
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  1288
  Klass* _klass;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
  jvmtiHeapObjectFilter _object_filter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
  jvmtiHeapObjectCallback _heap_object_callback;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
  const void* _user_data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
  JvmtiTagMap* tag_map() const                    { return _tag_map; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
  jvmtiHeapObjectFilter object_filter() const     { return _object_filter; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
  jvmtiHeapObjectCallback object_callback() const { return _heap_object_callback; }
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  1297
  Klass* klass() const                            { return _klass; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
  const void* user_data() const                   { return _user_data; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
  // indicates if iteration has been aborted
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
  bool _iteration_aborted;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
  bool is_iteration_aborted() const               { return _iteration_aborted; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
  void set_iteration_aborted(bool aborted)        { _iteration_aborted = aborted; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
  IterateOverHeapObjectClosure(JvmtiTagMap* tag_map,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  1307
                               Klass* klass,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
                               jvmtiHeapObjectFilter object_filter,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
                               jvmtiHeapObjectCallback heap_object_callback,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
                               const void* user_data) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
    _tag_map(tag_map),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
    _klass(klass),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
    _object_filter(object_filter),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
    _heap_object_callback(heap_object_callback),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
    _user_data(user_data),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
    _iteration_aborted(false)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
  void do_object(oop o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
// invoked for each object in the heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
void IterateOverHeapObjectClosure::do_object(oop o) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
  // check if iteration has been halted
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
  if (is_iteration_aborted()) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
  // instanceof check when filtering by klass
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  1329
  if (klass() != NULL && !o->is_a(klass())) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
  // prepare for the calllback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
  CallbackWrapper wrapper(tag_map(), o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
  // if the object is tagged and we're only interested in untagged objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
  // then don't invoke the callback. Similiarly, if the object is untagged
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
  // and we're only interested in tagged objects we skip the callback.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
  if (wrapper.obj_tag() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
    if (object_filter() == JVMTI_HEAP_OBJECT_UNTAGGED) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
    if (object_filter() == JVMTI_HEAP_OBJECT_TAGGED) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
  // invoke the agent's callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
  jvmtiIterationControl control = (*object_callback())(wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
                                                       wrapper.obj_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
                                                       wrapper.obj_tag_p(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
                                                       (void*)user_data());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
  if (control == JVMTI_ITERATION_ABORT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
    set_iteration_aborted(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
// An ObjectClosure used to support the IterateThroughHeap function
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
class IterateThroughHeapObjectClosure: public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
  JvmtiTagMap* _tag_map;
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  1358
  Klass* _klass;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
  int _heap_filter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
  const jvmtiHeapCallbacks* _callbacks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
  const void* _user_data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
  // accessor functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
  JvmtiTagMap* tag_map() const                     { return _tag_map; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
  int heap_filter() const                          { return _heap_filter; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
  const jvmtiHeapCallbacks* callbacks() const      { return _callbacks; }
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  1367
  Klass* klass() const                             { return _klass; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
  const void* user_data() const                    { return _user_data; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
  // indicates if the iteration has been aborted
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
  bool _iteration_aborted;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
  bool is_iteration_aborted() const                { return _iteration_aborted; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
  // used to check the visit control flags. If the abort flag is set
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
  // then we set the iteration aborted flag so that the iteration completes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
  // without processing any further objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
  bool check_flags_for_abort(jint flags) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
    bool is_abort = (flags & JVMTI_VISIT_ABORT) != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
    if (is_abort) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
      _iteration_aborted = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
    return is_abort;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
  IterateThroughHeapObjectClosure(JvmtiTagMap* tag_map,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  1387
                                  Klass* klass,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
                                  int heap_filter,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
                                  const jvmtiHeapCallbacks* heap_callbacks,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
                                  const void* user_data) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
    _tag_map(tag_map),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
    _klass(klass),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
    _heap_filter(heap_filter),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
    _callbacks(heap_callbacks),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
    _user_data(user_data),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
    _iteration_aborted(false)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
  void do_object(oop o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
// invoked for each object in the heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
void IterateThroughHeapObjectClosure::do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
  // check if iteration has been halted
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
  if (is_iteration_aborted()) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
  // apply class filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
  if (is_filtered_by_klass_filter(obj, klass())) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
  // prepare for callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
  CallbackWrapper wrapper(tag_map(), obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
  // check if filtered by the heap filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
  if (is_filtered_by_heap_filter(wrapper.obj_tag(), wrapper.klass_tag(), heap_filter())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
  // for arrays we need the length, otherwise -1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
  bool is_array = obj->is_array();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
  int len = is_array ? arrayOop(obj)->length() : -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
  // invoke the object callback (if callback is provided)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
  if (callbacks()->heap_iteration_callback != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
    jvmtiHeapIterationCallback cb = callbacks()->heap_iteration_callback;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
    jint res = (*cb)(wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
                     wrapper.obj_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
                     wrapper.obj_tag_p(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
                     (jint)len,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
                     (void*)user_data());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
    if (check_flags_for_abort(res)) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
  // for objects and classes we report primitive fields if callback provided
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
  if (callbacks()->primitive_field_callback != NULL && obj->is_instance()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
    jint res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
    jvmtiPrimitiveFieldCallback cb = callbacks()->primitive_field_callback;
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 3908
diff changeset
  1438
    if (obj->klass() == SystemDictionary::Class_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
      res = invoke_primitive_field_callback_for_static_fields(&wrapper,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
                                                                    obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
                                                                    cb,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
                                                                    (void*)user_data());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
      res = invoke_primitive_field_callback_for_instance_fields(&wrapper,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
                                                                      obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
                                                                      cb,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
                                                                      (void*)user_data());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
    if (check_flags_for_abort(res)) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
  // string callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
  if (!is_array &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
      callbacks()->string_primitive_value_callback != NULL &&
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 3908
diff changeset
  1455
      obj->klass() == SystemDictionary::String_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
    jint res = invoke_string_value_callback(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
                callbacks()->string_primitive_value_callback,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
                &wrapper,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
                obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
                (void*)user_data() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
    if (check_flags_for_abort(res)) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
  // array callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
  if (is_array &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
      callbacks()->array_primitive_value_callback != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
      obj->is_typeArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
    jint res = invoke_array_primitive_value_callback(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
               callbacks()->array_primitive_value_callback,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
               &wrapper,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
               obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
               (void*)user_data() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
    if (check_flags_for_abort(res)) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
// Deprecated function to iterate over all objects in the heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
void JvmtiTagMap::iterate_over_heap(jvmtiHeapObjectFilter object_filter,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  1480
                                    Klass* klass,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
                                    jvmtiHeapObjectCallback heap_object_callback,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
                                    const void* user_data)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
  MutexLocker ml(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
  IterateOverHeapObjectClosure blk(this,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
                                   klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
                                   object_filter,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
                                   heap_object_callback,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
                                   user_data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
  VM_HeapIterateOperation op(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
  VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
// Iterates over all objects in the heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
void JvmtiTagMap::iterate_through_heap(jint heap_filter,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  1497
                                       Klass* klass,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
                                       const jvmtiHeapCallbacks* callbacks,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
                                       const void* user_data)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
  MutexLocker ml(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
  IterateThroughHeapObjectClosure blk(this,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
                                      klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
                                      heap_filter,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
                                      callbacks,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
                                      user_data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
  VM_HeapIterateOperation op(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
  VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
// support class for get_objects_with_tags
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
class TagObjectCollector : public JvmtiTagHashmapEntryClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
  JvmtiEnv* _env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
  jlong* _tags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
  jint _tag_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
  GrowableArray<jobject>* _object_results;  // collected objects (JNI weak refs)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
  GrowableArray<uint64_t>* _tag_results;    // collected tags
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
  TagObjectCollector(JvmtiEnv* env, const jlong* tags, jint tag_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
    _env = env;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
    _tags = (jlong*)tags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
    _tag_count = tag_count;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13096
diff changeset
  1527
    _object_results = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jobject>(1,true);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13096
diff changeset
  1528
    _tag_results = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<uint64_t>(1,true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
  ~TagObjectCollector() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
    delete _object_results;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
    delete _tag_results;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
  // for each tagged object check if the tag value matches
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
  // - if it matches then we create a JNI local reference to the object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
  // and record the reference and tag value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
  void do_entry(JvmtiTagHashmapEntry* entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
    for (int i=0; i<_tag_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
      if (_tags[i] == entry->tag()) {
48616
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
  1543
        // The reference in this tag map could be the only (implicitly weak)
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
  1544
        // reference to that object. If we hand it out, we need to keep it live wrt
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
  1545
        // SATB marking similar to other j.l.ref.Reference referents. This is
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
  1546
        // achieved by using a phantom load in the object() accessor.
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  1547
        oop o = entry->object();
58015
dd84de796f2c 8224815: Remove non-GC uses of CollectedHeap::is_in_reserved()
eosterlund
parents: 57812
diff changeset
  1548
        assert(o != NULL && Universe::heap()->is_in(o), "sanity check");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
        jobject ref = JNIHandles::make_local(JavaThread::current(), o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
        _object_results->append(ref);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
        _tag_results->append((uint64_t)entry->tag());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
  // return the results from the collection
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
  jvmtiError result(jint* count_ptr, jobject** object_result_ptr, jlong** tag_result_ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
    jvmtiError error;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
    int count = _object_results->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
    assert(count >= 0, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
    // if object_result_ptr is not NULL then allocate the result and copy
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
    // in the object references.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
    if (object_result_ptr != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
      error = _env->Allocate(count * sizeof(jobject), (unsigned char**)object_result_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
      if (error != JVMTI_ERROR_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
        return error;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
      for (int i=0; i<count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
        (*object_result_ptr)[i] = _object_results->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
    // if tag_result_ptr is not NULL then allocate the result and copy
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
    // in the tag values.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
    if (tag_result_ptr != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
      error = _env->Allocate(count * sizeof(jlong), (unsigned char**)tag_result_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
      if (error != JVMTI_ERROR_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
        if (object_result_ptr != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
          _env->Deallocate((unsigned char*)object_result_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
        return error;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
      for (int i=0; i<count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
        (*tag_result_ptr)[i] = (jlong)_tag_results->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
    *count_ptr = count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
    return JVMTI_ERROR_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
// return the list of objects with the specified tags
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
jvmtiError JvmtiTagMap::get_objects_with_tags(const jlong* tags,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
  jint count, jint* count_ptr, jobject** object_result_ptr, jlong** tag_result_ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
  TagObjectCollector collector(env(), tags, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
    // iterate over all tagged objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
    MutexLocker ml(lock());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
    entry_iterate(&collector);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
  return collector.result(count_ptr, object_result_ptr, tag_result_ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
// ObjectMarker is used to support the marking objects when walking the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
// heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
// This implementation uses the existing mark bits in an object for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
// marking. Objects that are marked must later have their headers restored.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
// As most objects are unlocked and don't have their identity hash computed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
// we don't have to save their headers. Instead we save the headers that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
// are "interesting". Later when the headers are restored this implementation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
// restores all headers to their initial value and then restores the few
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
// objects that had interesting headers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
// Future work: This implementation currently uses growable arrays to save
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
// the oop and header of interesting objects. As an optimization we could
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
// use the same technique as the GC and make use of the unused area
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
// between top() and end().
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1624
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
// An ObjectClosure used to restore the mark bits of an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
class RestoreMarksClosure : public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
  void do_object(oop o) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
    if (o != NULL) {
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 57745
diff changeset
  1631
      markWord mark = o->mark();
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 57745
diff changeset
  1632
      if (mark.is_marked()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
        o->init_mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
// ObjectMarker provides the mark and visited functions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
class ObjectMarker : AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
  // saved headers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
  static GrowableArray<oop>* _saved_oop_stack;
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 57745
diff changeset
  1644
  static GrowableArray<markWord>* _saved_mark_stack;
10228
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  1645
  static bool _needs_reset;                  // do we need to reset mark bits?
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
  static void init();                       // initialize
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
  static void done();                       // clean-up
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
  static inline void mark(oop o);           // mark an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
  static inline bool visited(oop o);        // check if object has been visited
10228
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  1653
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  1654
  static inline bool needs_reset()            { return _needs_reset; }
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  1655
  static inline void set_needs_reset(bool v)  { _needs_reset = v; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
GrowableArray<oop>* ObjectMarker::_saved_oop_stack = NULL;
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 57745
diff changeset
  1659
GrowableArray<markWord>* ObjectMarker::_saved_mark_stack = NULL;
10228
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  1660
bool ObjectMarker::_needs_reset = true;  // need to reset mark bits by default
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
// initialize ObjectMarker - prepares for object marking
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
void ObjectMarker::init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
  assert(Thread::current()->is_VM_thread(), "must be VMThread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
  // prepare heap for iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
  Universe::heap()->ensure_parsability(false);  // no need to retire TLABs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
  // create stacks for interesting headers
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 57745
diff changeset
  1670
  _saved_mark_stack = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<markWord>(4000, true);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13096
diff changeset
  1671
  _saved_oop_stack = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(4000, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
  if (UseBiasedLocking) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
    BiasedLocking::preserve_marks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
// Object marking is done so restore object headers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
void ObjectMarker::done() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
  // iterate over all objects and restore the mark bits to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
  // their initial value
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
  RestoreMarksClosure blk;
10228
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  1683
  if (needs_reset()) {
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  1684
    Universe::heap()->object_iterate(&blk);
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  1685
  } else {
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  1686
    // We don't need to reset mark bits on this call, but reset the
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  1687
    // flag to the default for the next call.
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  1688
    set_needs_reset(true);
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  1689
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
  // now restore the interesting headers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
  for (int i = 0; i < _saved_oop_stack->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
    oop o = _saved_oop_stack->at(i);
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 57745
diff changeset
  1694
    markWord mark = _saved_mark_stack->at(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
    o->set_mark(mark);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
  if (UseBiasedLocking) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
    BiasedLocking::restore_marks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
  // free the stacks
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
  delete _saved_oop_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
  delete _saved_mark_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
// mark an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
inline void ObjectMarker::mark(oop o) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
  assert(Universe::heap()->is_in(o), "sanity check");
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 57745
diff changeset
  1710
  assert(!o->mark().is_marked(), "should only mark an object once");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
  // object's mark word
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 57745
diff changeset
  1713
  markWord mark = o->mark();
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 57745
diff changeset
  1714
57812
9bb28ccc6106 8229839: Break circular dependency between oop.inline.hpp and markWord.inline.hpp
stefank
parents: 57777
diff changeset
  1715
  if (o->mark_must_be_preserved(mark)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
    _saved_mark_stack->push(mark);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
    _saved_oop_stack->push(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
  // mark the object
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 57745
diff changeset
  1721
  o->set_mark(markWord::prototype().set_marked());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
// return true if object is marked
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
inline bool ObjectMarker::visited(oop o) {
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 57745
diff changeset
  1726
  return o->mark().is_marked();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
// Stack allocated class to help ensure that ObjectMarker is used
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
// correctly. Constructor initializes ObjectMarker, destructor calls
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
// ObjectMarker's done() function to restore object headers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
class ObjectMarkerController : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
  ObjectMarkerController() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
    ObjectMarker::init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
  ~ObjectMarkerController() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
    ObjectMarker::done();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
// helper to map a jvmtiHeapReferenceKind to an old style jvmtiHeapRootKind
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
// (not performance critical as only used for roots)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
static jvmtiHeapRootKind toJvmtiHeapRootKind(jvmtiHeapReferenceKind kind) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
  switch (kind) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
    case JVMTI_HEAP_REFERENCE_JNI_GLOBAL:   return JVMTI_HEAP_ROOT_JNI_GLOBAL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
    case JVMTI_HEAP_REFERENCE_SYSTEM_CLASS: return JVMTI_HEAP_ROOT_SYSTEM_CLASS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
    case JVMTI_HEAP_REFERENCE_MONITOR:      return JVMTI_HEAP_ROOT_MONITOR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
    case JVMTI_HEAP_REFERENCE_STACK_LOCAL:  return JVMTI_HEAP_ROOT_STACK_LOCAL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
    case JVMTI_HEAP_REFERENCE_JNI_LOCAL:    return JVMTI_HEAP_ROOT_JNI_LOCAL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
    case JVMTI_HEAP_REFERENCE_THREAD:       return JVMTI_HEAP_ROOT_THREAD;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
    case JVMTI_HEAP_REFERENCE_OTHER:        return JVMTI_HEAP_ROOT_OTHER;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
    default: ShouldNotReachHere();          return JVMTI_HEAP_ROOT_OTHER;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
// Base class for all heap walk contexts. The base class maintains a flag
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
// to indicate if the context is valid or not.
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 49360
diff changeset
  1760
class HeapWalkContext {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
  bool _valid;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
  HeapWalkContext(bool valid)                   { _valid = valid; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
  void invalidate()                             { _valid = false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
  bool is_valid() const                         { return _valid; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
// A basic heap walk context for the deprecated heap walking functions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
// The context for a basic heap walk are the callbacks and fields used by
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
// the referrer caching scheme.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
class BasicHeapWalkContext: public HeapWalkContext {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
  jvmtiHeapRootCallback _heap_root_callback;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
  jvmtiStackReferenceCallback _stack_ref_callback;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
  jvmtiObjectReferenceCallback _object_ref_callback;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
  // used for caching
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
  oop _last_referrer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
  jlong _last_referrer_tag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
  BasicHeapWalkContext() : HeapWalkContext(false) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
  BasicHeapWalkContext(jvmtiHeapRootCallback heap_root_callback,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
                       jvmtiStackReferenceCallback stack_ref_callback,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
                       jvmtiObjectReferenceCallback object_ref_callback) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
    HeapWalkContext(true),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
    _heap_root_callback(heap_root_callback),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
    _stack_ref_callback(stack_ref_callback),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
    _object_ref_callback(object_ref_callback),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
    _last_referrer(NULL),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
    _last_referrer_tag(0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
  jvmtiHeapRootCallback heap_root_callback() const         { return _heap_root_callback; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
  jvmtiStackReferenceCallback stack_ref_callback() const   { return _stack_ref_callback; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
  jvmtiObjectReferenceCallback object_ref_callback() const { return _object_ref_callback;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
  oop last_referrer() const               { return _last_referrer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
  void set_last_referrer(oop referrer)    { _last_referrer = referrer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
  jlong last_referrer_tag() const         { return _last_referrer_tag; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
  void set_last_referrer_tag(jlong value) { _last_referrer_tag = value; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
// The advanced heap walk context for the FollowReferences functions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
// The context is the callbacks, and the fields used for filtering.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
class AdvancedHeapWalkContext: public HeapWalkContext {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
  jint _heap_filter;
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  1812
  Klass* _klass_filter;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
  const jvmtiHeapCallbacks* _heap_callbacks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
  AdvancedHeapWalkContext() : HeapWalkContext(false) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
  AdvancedHeapWalkContext(jint heap_filter,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  1819
                           Klass* klass_filter,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
                           const jvmtiHeapCallbacks* heap_callbacks) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
    HeapWalkContext(true),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
    _heap_filter(heap_filter),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
    _klass_filter(klass_filter),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
    _heap_callbacks(heap_callbacks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
  jint heap_filter() const         { return _heap_filter; }
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  1829
  Klass* klass_filter() const      { return _klass_filter; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
  const jvmtiHeapReferenceCallback heap_reference_callback() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
    return _heap_callbacks->heap_reference_callback;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
  const jvmtiPrimitiveFieldCallback primitive_field_callback() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
    return _heap_callbacks->primitive_field_callback;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
  const jvmtiArrayPrimitiveValueCallback array_primitive_value_callback() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
    return _heap_callbacks->array_primitive_value_callback;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1840
  const jvmtiStringPrimitiveValueCallback string_primitive_value_callback() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1841
    return _heap_callbacks->string_primitive_value_callback;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1844
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
// The CallbackInvoker is a class with static functions that the heap walk can call
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
// into to invoke callbacks. It works in one of two modes. The "basic" mode is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
// used for the deprecated IterateOverReachableObjects functions. The "advanced"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
// mode is for the newer FollowReferences function which supports a lot of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
// additional callbacks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
class CallbackInvoker : AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
  // heap walk styles
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
  enum { basic, advanced };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
  static int _heap_walk_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1855
  static bool is_basic_heap_walk()           { return _heap_walk_type == basic; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1856
  static bool is_advanced_heap_walk()        { return _heap_walk_type == advanced; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1857
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
  // context for basic style heap walk
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
  static BasicHeapWalkContext _basic_context;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
  static BasicHeapWalkContext* basic_context() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
    assert(_basic_context.is_valid(), "invalid");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
    return &_basic_context;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
  // context for advanced style heap walk
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
  static AdvancedHeapWalkContext _advanced_context;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
  static AdvancedHeapWalkContext* advanced_context() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
    assert(_advanced_context.is_valid(), "invalid");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
    return &_advanced_context;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1872
  // context needed for all heap walks
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1873
  static JvmtiTagMap* _tag_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1874
  static const void* _user_data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1875
  static GrowableArray<oop>* _visit_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1876
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1877
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1878
  static JvmtiTagMap* tag_map()                        { return _tag_map; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1879
  static const void* user_data()                       { return _user_data; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1880
  static GrowableArray<oop>* visit_stack()             { return _visit_stack; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1882
  // if the object hasn't been visited then push it onto the visit stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1883
  // so that it will be visited later
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
  static inline bool check_for_visit(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
    if (!ObjectMarker::visited(obj)) visit_stack()->push(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1887
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1888
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1889
  // invoke basic style callbacks
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1890
  static inline bool invoke_basic_heap_root_callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
    (jvmtiHeapRootKind root_kind, oop obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
  static inline bool invoke_basic_stack_ref_callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
    (jvmtiHeapRootKind root_kind, jlong thread_tag, jint depth, jmethodID method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
     int slot, oop obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
  static inline bool invoke_basic_object_reference_callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1896
    (jvmtiObjectReferenceKind ref_kind, oop referrer, oop referree, jint index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
  // invoke advanced style callbacks
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
  static inline bool invoke_advanced_heap_root_callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
    (jvmtiHeapReferenceKind ref_kind, oop obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
  static inline bool invoke_advanced_stack_ref_callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
    (jvmtiHeapReferenceKind ref_kind, jlong thread_tag, jlong tid, int depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
     jmethodID method, jlocation bci, jint slot, oop obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
  static inline bool invoke_advanced_object_reference_callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
    (jvmtiHeapReferenceKind ref_kind, oop referrer, oop referree, jint index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
  // used to report the value of primitive fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
  static inline bool report_primitive_field
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
    (jvmtiHeapReferenceKind ref_kind, oop obj, jint index, address addr, char type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1912
  // initialize for basic mode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1913
  static void initialize_for_basic_heap_walk(JvmtiTagMap* tag_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1914
                                             GrowableArray<oop>* visit_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1915
                                             const void* user_data,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1916
                                             BasicHeapWalkContext context);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1917
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1918
  // initialize for advanced mode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1919
  static void initialize_for_advanced_heap_walk(JvmtiTagMap* tag_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1920
                                                GrowableArray<oop>* visit_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1921
                                                const void* user_data,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1922
                                                AdvancedHeapWalkContext context);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1923
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1924
   // functions to report roots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1925
  static inline bool report_simple_root(jvmtiHeapReferenceKind kind, oop o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1926
  static inline bool report_jni_local_root(jlong thread_tag, jlong tid, jint depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1927
    jmethodID m, oop o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1928
  static inline bool report_stack_ref_root(jlong thread_tag, jlong tid, jint depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1929
    jmethodID method, jlocation bci, jint slot, oop o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1930
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1931
  // functions to report references
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1932
  static inline bool report_array_element_reference(oop referrer, oop referree, jint index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1933
  static inline bool report_class_reference(oop referrer, oop referree);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1934
  static inline bool report_class_loader_reference(oop referrer, oop referree);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1935
  static inline bool report_signers_reference(oop referrer, oop referree);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1936
  static inline bool report_protection_domain_reference(oop referrer, oop referree);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1937
  static inline bool report_superclass_reference(oop referrer, oop referree);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1938
  static inline bool report_interface_reference(oop referrer, oop referree);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1939
  static inline bool report_static_field_reference(oop referrer, oop referree, jint slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1940
  static inline bool report_field_reference(oop referrer, oop referree, jint slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1941
  static inline bool report_constant_pool_reference(oop referrer, oop referree, jint index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1942
  static inline bool report_primitive_array_values(oop array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1943
  static inline bool report_string_value(oop str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1944
  static inline bool report_primitive_instance_field(oop o, jint index, address value, char type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1945
  static inline bool report_primitive_static_field(oop o, jint index, address value, char type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1946
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1947
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1948
// statics
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1949
int CallbackInvoker::_heap_walk_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1950
BasicHeapWalkContext CallbackInvoker::_basic_context;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1951
AdvancedHeapWalkContext CallbackInvoker::_advanced_context;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1952
JvmtiTagMap* CallbackInvoker::_tag_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1953
const void* CallbackInvoker::_user_data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1954
GrowableArray<oop>* CallbackInvoker::_visit_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1955
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1956
// initialize for basic heap walk (IterateOverReachableObjects et al)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1957
void CallbackInvoker::initialize_for_basic_heap_walk(JvmtiTagMap* tag_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1958
                                                     GrowableArray<oop>* visit_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1959
                                                     const void* user_data,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1960
                                                     BasicHeapWalkContext context) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1961
  _tag_map = tag_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1962
  _visit_stack = visit_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1963
  _user_data = user_data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1964
  _basic_context = context;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1965
  _advanced_context.invalidate();       // will trigger assertion if used
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1966
  _heap_walk_type = basic;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1967
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1968
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1969
// initialize for advanced heap walk (FollowReferences)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1970
void CallbackInvoker::initialize_for_advanced_heap_walk(JvmtiTagMap* tag_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1971
                                                        GrowableArray<oop>* visit_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1972
                                                        const void* user_data,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1973
                                                        AdvancedHeapWalkContext context) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1974
  _tag_map = tag_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1975
  _visit_stack = visit_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1976
  _user_data = user_data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1977
  _advanced_context = context;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1978
  _basic_context.invalidate();      // will trigger assertion if used
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1979
  _heap_walk_type = advanced;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1980
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1981
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1982
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1983
// invoke basic style heap root callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1984
inline bool CallbackInvoker::invoke_basic_heap_root_callback(jvmtiHeapRootKind root_kind, oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1985
  // if we heap roots should be reported
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1986
  jvmtiHeapRootCallback cb = basic_context()->heap_root_callback();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1987
  if (cb == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1988
    return check_for_visit(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1989
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1990
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1991
  CallbackWrapper wrapper(tag_map(), obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1992
  jvmtiIterationControl control = (*cb)(root_kind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1993
                                        wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1994
                                        wrapper.obj_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1995
                                        wrapper.obj_tag_p(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1996
                                        (void*)user_data());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1997
  // push root to visit stack when following references
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1998
  if (control == JVMTI_ITERATION_CONTINUE &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1999
      basic_context()->object_ref_callback() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2000
    visit_stack()->push(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2001
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2002
  return control != JVMTI_ITERATION_ABORT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2003
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2004
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2005
// invoke basic style stack ref callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2006
inline bool CallbackInvoker::invoke_basic_stack_ref_callback(jvmtiHeapRootKind root_kind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2007
                                                             jlong thread_tag,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2008
                                                             jint depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2009
                                                             jmethodID method,
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47580
diff changeset
  2010
                                                             int slot,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2011
                                                             oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2012
  // if we stack refs should be reported
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2013
  jvmtiStackReferenceCallback cb = basic_context()->stack_ref_callback();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2014
  if (cb == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2015
    return check_for_visit(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2016
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2017
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2018
  CallbackWrapper wrapper(tag_map(), obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2019
  jvmtiIterationControl control = (*cb)(root_kind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2020
                                        wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2021
                                        wrapper.obj_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2022
                                        wrapper.obj_tag_p(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2023
                                        thread_tag,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2024
                                        depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2025
                                        method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2026
                                        slot,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2027
                                        (void*)user_data());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2028
  // push root to visit stack when following references
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2029
  if (control == JVMTI_ITERATION_CONTINUE &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2030
      basic_context()->object_ref_callback() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2031
    visit_stack()->push(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2032
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2033
  return control != JVMTI_ITERATION_ABORT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2034
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2035
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2036
// invoke basic style object reference callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2037
inline bool CallbackInvoker::invoke_basic_object_reference_callback(jvmtiObjectReferenceKind ref_kind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2038
                                                                    oop referrer,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2039
                                                                    oop referree,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2040
                                                                    jint index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2041
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2042
  BasicHeapWalkContext* context = basic_context();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2043
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2044
  // callback requires the referrer's tag. If it's the same referrer
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2045
  // as the last call then we use the cached value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2046
  jlong referrer_tag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2047
  if (referrer == context->last_referrer()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2048
    referrer_tag = context->last_referrer_tag();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2049
  } else {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  2050
    referrer_tag = tag_for(tag_map(), referrer);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2051
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2052
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2053
  // do the callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2054
  CallbackWrapper wrapper(tag_map(), referree);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2055
  jvmtiObjectReferenceCallback cb = context->object_ref_callback();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2056
  jvmtiIterationControl control = (*cb)(ref_kind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2057
                                        wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2058
                                        wrapper.obj_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2059
                                        wrapper.obj_tag_p(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2060
                                        referrer_tag,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2061
                                        index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2062
                                        (void*)user_data());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2063
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2064
  // record referrer and referrer tag. For self-references record the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2065
  // tag value from the callback as this might differ from referrer_tag.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2066
  context->set_last_referrer(referrer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2067
  if (referrer == referree) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2068
    context->set_last_referrer_tag(*wrapper.obj_tag_p());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2069
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2070
    context->set_last_referrer_tag(referrer_tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2071
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2072
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2073
  if (control == JVMTI_ITERATION_CONTINUE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2074
    return check_for_visit(referree);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2075
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2076
    return control != JVMTI_ITERATION_ABORT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2077
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2078
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2079
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2080
// invoke advanced style heap root callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2081
inline bool CallbackInvoker::invoke_advanced_heap_root_callback(jvmtiHeapReferenceKind ref_kind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2082
                                                                oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2083
  AdvancedHeapWalkContext* context = advanced_context();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2084
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2085
  // check that callback is provided
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2086
  jvmtiHeapReferenceCallback cb = context->heap_reference_callback();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2087
  if (cb == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2088
    return check_for_visit(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2089
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2090
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2091
  // apply class filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2092
  if (is_filtered_by_klass_filter(obj, context->klass_filter())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2093
    return check_for_visit(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2094
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2095
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2096
  // setup the callback wrapper
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2097
  CallbackWrapper wrapper(tag_map(), obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2098
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2099
  // apply tag filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2100
  if (is_filtered_by_heap_filter(wrapper.obj_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2101
                                 wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2102
                                 context->heap_filter())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2103
    return check_for_visit(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2105
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2106
  // for arrays we need the length, otherwise -1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2107
  jint len = (jint)(obj->is_array() ? arrayOop(obj)->length() : -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2108
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2109
  // invoke the callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2110
  jint res  = (*cb)(ref_kind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2111
                    NULL, // referrer info
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2112
                    wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2113
                    0,    // referrer_class_tag is 0 for heap root
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2114
                    wrapper.obj_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2115
                    wrapper.obj_tag_p(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2116
                    NULL, // referrer_tag_p
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2117
                    len,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2118
                    (void*)user_data());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2119
  if (res & JVMTI_VISIT_ABORT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2120
    return false;// referrer class tag
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2121
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2122
  if (res & JVMTI_VISIT_OBJECTS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2123
    check_for_visit(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2125
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2126
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2127
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2128
// report a reference from a thread stack to an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2129
inline bool CallbackInvoker::invoke_advanced_stack_ref_callback(jvmtiHeapReferenceKind ref_kind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2130
                                                                jlong thread_tag,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2131
                                                                jlong tid,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2132
                                                                int depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2133
                                                                jmethodID method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2134
                                                                jlocation bci,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2135
                                                                jint slot,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2136
                                                                oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2137
  AdvancedHeapWalkContext* context = advanced_context();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2138
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2139
  // check that callback is provider
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2140
  jvmtiHeapReferenceCallback cb = context->heap_reference_callback();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2141
  if (cb == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2142
    return check_for_visit(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2144
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2145
  // apply class filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2146
  if (is_filtered_by_klass_filter(obj, context->klass_filter())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2147
    return check_for_visit(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2149
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2150
  // setup the callback wrapper
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2151
  CallbackWrapper wrapper(tag_map(), obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2152
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2153
  // apply tag filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2154
  if (is_filtered_by_heap_filter(wrapper.obj_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2155
                                 wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2156
                                 context->heap_filter())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2157
    return check_for_visit(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2159
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2160
  // setup the referrer info
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2161
  jvmtiHeapReferenceInfo reference_info;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2162
  reference_info.stack_local.thread_tag = thread_tag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2163
  reference_info.stack_local.thread_id = tid;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2164
  reference_info.stack_local.depth = depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2165
  reference_info.stack_local.method = method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2166
  reference_info.stack_local.location = bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2167
  reference_info.stack_local.slot = slot;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2168
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2169
  // for arrays we need the length, otherwise -1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2170
  jint len = (jint)(obj->is_array() ? arrayOop(obj)->length() : -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2171
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2172
  // call into the agent
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2173
  int res = (*cb)(ref_kind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2174
                  &reference_info,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2175
                  wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2176
                  0,    // referrer_class_tag is 0 for heap root (stack)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2177
                  wrapper.obj_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2178
                  wrapper.obj_tag_p(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2179
                  NULL, // referrer_tag is 0 for root
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2180
                  len,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2181
                  (void*)user_data());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2182
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2183
  if (res & JVMTI_VISIT_ABORT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2184
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2186
  if (res & JVMTI_VISIT_OBJECTS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2187
    check_for_visit(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2188
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2189
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2190
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2191
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2192
// This mask is used to pass reference_info to a jvmtiHeapReferenceCallback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2193
// only for ref_kinds defined by the JVM TI spec. Otherwise, NULL is passed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2194
#define REF_INFO_MASK  ((1 << JVMTI_HEAP_REFERENCE_FIELD)         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2195
                      | (1 << JVMTI_HEAP_REFERENCE_STATIC_FIELD)  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2196
                      | (1 << JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2197
                      | (1 << JVMTI_HEAP_REFERENCE_CONSTANT_POOL) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2198
                      | (1 << JVMTI_HEAP_REFERENCE_STACK_LOCAL)   \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2199
                      | (1 << JVMTI_HEAP_REFERENCE_JNI_LOCAL))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2200
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2201
// invoke the object reference callback to report a reference
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2202
inline bool CallbackInvoker::invoke_advanced_object_reference_callback(jvmtiHeapReferenceKind ref_kind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2203
                                                                       oop referrer,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2204
                                                                       oop obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2205
                                                                       jint index)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2206
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2207
  // field index is only valid field in reference_info
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2208
  static jvmtiHeapReferenceInfo reference_info = { 0 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2209
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2210
  AdvancedHeapWalkContext* context = advanced_context();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2211
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2212
  // check that callback is provider
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2213
  jvmtiHeapReferenceCallback cb = context->heap_reference_callback();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2214
  if (cb == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2215
    return check_for_visit(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2216
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2217
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2218
  // apply class filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2219
  if (is_filtered_by_klass_filter(obj, context->klass_filter())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2220
    return check_for_visit(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2221
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2222
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2223
  // setup the callback wrapper
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2224
  TwoOopCallbackWrapper wrapper(tag_map(), referrer, obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2225
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2226
  // apply tag filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2227
  if (is_filtered_by_heap_filter(wrapper.obj_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2228
                                 wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2229
                                 context->heap_filter())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2230
    return check_for_visit(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2231
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2232
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2233
  // field index is only valid field in reference_info
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2234
  reference_info.field.index = index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2235
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2236
  // for arrays we need the length, otherwise -1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2237
  jint len = (jint)(obj->is_array() ? arrayOop(obj)->length() : -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2238
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2239
  // invoke the callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2240
  int res = (*cb)(ref_kind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2241
                  (REF_INFO_MASK & (1 << ref_kind)) ? &reference_info : NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2242
                  wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2243
                  wrapper.referrer_klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2244
                  wrapper.obj_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2245
                  wrapper.obj_tag_p(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2246
                  wrapper.referrer_tag_p(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2247
                  len,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2248
                  (void*)user_data());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2249
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2250
  if (res & JVMTI_VISIT_ABORT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2251
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2252
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2253
  if (res & JVMTI_VISIT_OBJECTS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2254
    check_for_visit(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2256
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2257
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2258
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2259
// report a "simple root"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2260
inline bool CallbackInvoker::report_simple_root(jvmtiHeapReferenceKind kind, oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2261
  assert(kind != JVMTI_HEAP_REFERENCE_STACK_LOCAL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2262
         kind != JVMTI_HEAP_REFERENCE_JNI_LOCAL, "not a simple root");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2263
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2264
  if (is_basic_heap_walk()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2265
    // map to old style root kind
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2266
    jvmtiHeapRootKind root_kind = toJvmtiHeapRootKind(kind);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2267
    return invoke_basic_heap_root_callback(root_kind, obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2268
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2269
    assert(is_advanced_heap_walk(), "wrong heap walk type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2270
    return invoke_advanced_heap_root_callback(kind, obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2271
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2272
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2273
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2274
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2275
// invoke the primitive array values
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2276
inline bool CallbackInvoker::report_primitive_array_values(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2277
  assert(obj->is_typeArray(), "not a primitive array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2278
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2279
  AdvancedHeapWalkContext* context = advanced_context();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2280
  assert(context->array_primitive_value_callback() != NULL, "no callback");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2281
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2282
  // apply class filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2283
  if (is_filtered_by_klass_filter(obj, context->klass_filter())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2284
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2285
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2286
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2287
  CallbackWrapper wrapper(tag_map(), obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2288
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2289
  // apply tag filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2290
  if (is_filtered_by_heap_filter(wrapper.obj_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2291
                                 wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2292
                                 context->heap_filter())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2293
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2294
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2295
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2296
  // invoke the callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2297
  int res = invoke_array_primitive_value_callback(context->array_primitive_value_callback(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2298
                                                  &wrapper,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2299
                                                  obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2300
                                                  (void*)user_data());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2301
  return (!(res & JVMTI_VISIT_ABORT));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2302
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2303
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2304
// invoke the string value callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2305
inline bool CallbackInvoker::report_string_value(oop str) {
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 3908
diff changeset
  2306
  assert(str->klass() == SystemDictionary::String_klass(), "not a string");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2307
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2308
  AdvancedHeapWalkContext* context = advanced_context();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2309
  assert(context->string_primitive_value_callback() != NULL, "no callback");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2310
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2311
  // apply class filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2312
  if (is_filtered_by_klass_filter(str, context->klass_filter())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2313
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2314
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2315
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2316
  CallbackWrapper wrapper(tag_map(), str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2317
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2318
  // apply tag filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2319
  if (is_filtered_by_heap_filter(wrapper.obj_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2320
                                 wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2321
                                 context->heap_filter())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2322
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2323
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2324
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2325
  // invoke the callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2326
  int res = invoke_string_value_callback(context->string_primitive_value_callback(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2327
                                         &wrapper,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2328
                                         str,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2329
                                         (void*)user_data());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2330
  return (!(res & JVMTI_VISIT_ABORT));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2331
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2332
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2333
// invoke the primitive field callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2334
inline bool CallbackInvoker::report_primitive_field(jvmtiHeapReferenceKind ref_kind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2335
                                                    oop obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2336
                                                    jint index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2337
                                                    address addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2338
                                                    char type)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2339
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2340
  // for primitive fields only the index will be set
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2341
  static jvmtiHeapReferenceInfo reference_info = { 0 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2342
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2343
  AdvancedHeapWalkContext* context = advanced_context();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2344
  assert(context->primitive_field_callback() != NULL, "no callback");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2345
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2346
  // apply class filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2347
  if (is_filtered_by_klass_filter(obj, context->klass_filter())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2348
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2349
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2350
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2351
  CallbackWrapper wrapper(tag_map(), obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2352
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2353
  // apply tag filter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2354
  if (is_filtered_by_heap_filter(wrapper.obj_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2355
                                 wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2356
                                 context->heap_filter())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2357
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2358
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2359
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2360
  // the field index in the referrer
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2361
  reference_info.field.index = index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2362
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2363
  // map the type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2364
  jvmtiPrimitiveType value_type = (jvmtiPrimitiveType)type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2365
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2366
  // setup the jvalue
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2367
  jvalue value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2368
  copy_to_jvalue(&value, addr, value_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2369
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2370
  jvmtiPrimitiveFieldCallback cb = context->primitive_field_callback();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2371
  int res = (*cb)(ref_kind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2372
                  &reference_info,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2373
                  wrapper.klass_tag(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2374
                  wrapper.obj_tag_p(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2375
                  value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2376
                  value_type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2377
                  (void*)user_data());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2378
  return (!(res & JVMTI_VISIT_ABORT));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2379
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2380
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2381
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2382
// instance field
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2383
inline bool CallbackInvoker::report_primitive_instance_field(oop obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2384
                                                             jint index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2385
                                                             address value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2386
                                                             char type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2387
  return report_primitive_field(JVMTI_HEAP_REFERENCE_FIELD,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2388
                                obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2389
                                index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2390
                                value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2391
                                type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2392
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2393
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2394
// static field
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2395
inline bool CallbackInvoker::report_primitive_static_field(oop obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2396
                                                           jint index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2397
                                                           address value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2398
                                                           char type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2399
  return report_primitive_field(JVMTI_HEAP_REFERENCE_STATIC_FIELD,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2400
                                obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2401
                                index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2402
                                value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2403
                                type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2404
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2405
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2406
// report a JNI local (root object) to the profiler
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2407
inline bool CallbackInvoker::report_jni_local_root(jlong thread_tag, jlong tid, jint depth, jmethodID m, oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2408
  if (is_basic_heap_walk()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2409
    return invoke_basic_stack_ref_callback(JVMTI_HEAP_ROOT_JNI_LOCAL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2410
                                           thread_tag,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2411
                                           depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2412
                                           m,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2413
                                           -1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2414
                                           obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2415
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2416
    return invoke_advanced_stack_ref_callback(JVMTI_HEAP_REFERENCE_JNI_LOCAL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2417
                                              thread_tag, tid,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2418
                                              depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2419
                                              m,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2420
                                              (jlocation)-1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2421
                                              -1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2422
                                              obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2423
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2424
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2425
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2426
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2427
// report a local (stack reference, root object)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2428
inline bool CallbackInvoker::report_stack_ref_root(jlong thread_tag,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2429
                                                   jlong tid,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2430
                                                   jint depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2431
                                                   jmethodID method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2432
                                                   jlocation bci,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2433
                                                   jint slot,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2434
                                                   oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2435
  if (is_basic_heap_walk()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2436
    return invoke_basic_stack_ref_callback(JVMTI_HEAP_ROOT_STACK_LOCAL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2437
                                           thread_tag,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2438
                                           depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2439
                                           method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2440
                                           slot,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2441
                                           obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2442
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2443
    return invoke_advanced_stack_ref_callback(JVMTI_HEAP_REFERENCE_STACK_LOCAL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2444
                                              thread_tag,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2445
                                              tid,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2446
                                              depth,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2447
                                              method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2448
                                              bci,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2449
                                              slot,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2450
                                              obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2451
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2452
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2453
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2454
// report an object referencing a class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2455
inline bool CallbackInvoker::report_class_reference(oop referrer, oop referree) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2456
  if (is_basic_heap_walk()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2457
    return invoke_basic_object_reference_callback(JVMTI_REFERENCE_CLASS, referrer, referree, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2458
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2459
    return invoke_advanced_object_reference_callback(JVMTI_HEAP_REFERENCE_CLASS, referrer, referree, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2460
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2461
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2462
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2463
// report a class referencing its class loader.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2464
inline bool CallbackInvoker::report_class_loader_reference(oop referrer, oop referree) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2465
  if (is_basic_heap_walk()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2466
    return invoke_basic_object_reference_callback(JVMTI_REFERENCE_CLASS_LOADER, referrer, referree, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2467
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2468
    return invoke_advanced_object_reference_callback(JVMTI_HEAP_REFERENCE_CLASS_LOADER, referrer, referree, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2469
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2470
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2471
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2472
// report a class referencing its signers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2473
inline bool CallbackInvoker::report_signers_reference(oop referrer, oop referree) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2474
  if (is_basic_heap_walk()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2475
    return invoke_basic_object_reference_callback(JVMTI_REFERENCE_SIGNERS, referrer, referree, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2476
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2477
    return invoke_advanced_object_reference_callback(JVMTI_HEAP_REFERENCE_SIGNERS, referrer, referree, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2478
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2479
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2480
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2481
// report a class referencing its protection domain..
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2482
inline bool CallbackInvoker::report_protection_domain_reference(oop referrer, oop referree) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2483
  if (is_basic_heap_walk()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2484
    return invoke_basic_object_reference_callback(JVMTI_REFERENCE_PROTECTION_DOMAIN, referrer, referree, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2485
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2486
    return invoke_advanced_object_reference_callback(JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN, referrer, referree, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2487
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2488
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2489
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2490
// report a class referencing its superclass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2491
inline bool CallbackInvoker::report_superclass_reference(oop referrer, oop referree) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2492
  if (is_basic_heap_walk()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2493
    // Send this to be consistent with past implementation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2494
    return invoke_basic_object_reference_callback(JVMTI_REFERENCE_CLASS, referrer, referree, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2495
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2496
    return invoke_advanced_object_reference_callback(JVMTI_HEAP_REFERENCE_SUPERCLASS, referrer, referree, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2497
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2498
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2499
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2500
// report a class referencing one of its interfaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2501
inline bool CallbackInvoker::report_interface_reference(oop referrer, oop referree) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2502
  if (is_basic_heap_walk()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2503
    return invoke_basic_object_reference_callback(JVMTI_REFERENCE_INTERFACE, referrer, referree, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2504
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2505
    return invoke_advanced_object_reference_callback(JVMTI_HEAP_REFERENCE_INTERFACE, referrer, referree, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2506
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2507
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2508
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2509
// report a class referencing one of its static fields.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2510
inline bool CallbackInvoker::report_static_field_reference(oop referrer, oop referree, jint slot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2511
  if (is_basic_heap_walk()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2512
    return invoke_basic_object_reference_callback(JVMTI_REFERENCE_STATIC_FIELD, referrer, referree, slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2513
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2514
    return invoke_advanced_object_reference_callback(JVMTI_HEAP_REFERENCE_STATIC_FIELD, referrer, referree, slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2515
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2516
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2517
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2518
// report an array referencing an element object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2519
inline bool CallbackInvoker::report_array_element_reference(oop referrer, oop referree, jint index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2520
  if (is_basic_heap_walk()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2521
    return invoke_basic_object_reference_callback(JVMTI_REFERENCE_ARRAY_ELEMENT, referrer, referree, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2522
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2523
    return invoke_advanced_object_reference_callback(JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT, referrer, referree, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2524
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2525
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2526
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2527
// report an object referencing an instance field object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2528
inline bool CallbackInvoker::report_field_reference(oop referrer, oop referree, jint slot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2529
  if (is_basic_heap_walk()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2530
    return invoke_basic_object_reference_callback(JVMTI_REFERENCE_FIELD, referrer, referree, slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2531
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2532
    return invoke_advanced_object_reference_callback(JVMTI_HEAP_REFERENCE_FIELD, referrer, referree, slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2533
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2534
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2535
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2536
// report an array referencing an element object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2537
inline bool CallbackInvoker::report_constant_pool_reference(oop referrer, oop referree, jint index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2538
  if (is_basic_heap_walk()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2539
    return invoke_basic_object_reference_callback(JVMTI_REFERENCE_CONSTANT_POOL, referrer, referree, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2540
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2541
    return invoke_advanced_object_reference_callback(JVMTI_HEAP_REFERENCE_CONSTANT_POOL, referrer, referree, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2542
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2543
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2544
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2545
// A supporting closure used to process simple roots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2546
class SimpleRootsClosure : public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2547
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2548
  jvmtiHeapReferenceKind _kind;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2549
  bool _continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2550
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2551
  jvmtiHeapReferenceKind root_kind()    { return _kind; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2552
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2553
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2554
  void set_kind(jvmtiHeapReferenceKind kind) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2555
    _kind = kind;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2556
    _continue = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2557
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2558
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2559
  inline bool stopped() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2560
    return !_continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2561
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2562
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2563
  void do_oop(oop* obj_p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2564
    // iteration has terminated
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2565
    if (stopped()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2566
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2567
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2568
52652
d9d3b14b2cfa 8214068: ZGC crashes with vmTestbase/nsk/jdi/ReferenceType/instances/instances004/TestDescription.java
pliden
parents: 52179
diff changeset
  2569
    oop o = NativeAccess<AS_NO_KEEPALIVE>::oop_load(obj_p);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents: 48616
diff changeset
  2570
    // ignore null
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents: 48616
diff changeset
  2571
    if (o == NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2572
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2573
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2574
58015
dd84de796f2c 8224815: Remove non-GC uses of CollectedHeap::is_in_reserved()
eosterlund
parents: 57812
diff changeset
  2575
    assert(Universe::heap()->is_in(o), "should be impossible");
13741
e4395deb8597 7197350: NPG: jvmtiHeapReferenceCallback receives incorrect reference_kind for system class roots
stefank
parents: 13738
diff changeset
  2576
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2577
    jvmtiHeapReferenceKind kind = root_kind();
13741
e4395deb8597 7197350: NPG: jvmtiHeapReferenceCallback receives incorrect reference_kind for system class roots
stefank
parents: 13738
diff changeset
  2578
    if (kind == JVMTI_HEAP_REFERENCE_SYSTEM_CLASS) {
50297
580744d900c8 8202813: Move vm_weak processing from SystemDictionary to WeakProcessor
coleenp
parents: 49982
diff changeset
  2579
      // SystemDictionary::oops_do reports the application
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2580
      // class loader as a root. We want this root to be reported as
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2581
      // a root kind of "OTHER" rather than "SYSTEM_CLASS".
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
  2582
      if (!o->is_instance() || !InstanceKlass::cast(o->klass())->is_mirror_instance_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2583
        kind = JVMTI_HEAP_REFERENCE_OTHER;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2584
      }
13741
e4395deb8597 7197350: NPG: jvmtiHeapReferenceCallback receives incorrect reference_kind for system class roots
stefank
parents: 13738
diff changeset
  2585
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2586
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2587
    // invoke the callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2588
    _continue = CallbackInvoker::report_simple_root(kind, o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2589
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2590
  }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  2591
  virtual void do_oop(narrowOop* obj_p) { ShouldNotReachHere(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2592
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2593
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2594
// A supporting closure used to process JNI locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2595
class JNILocalRootsClosure : public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2596
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2597
  jlong _thread_tag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2598
  jlong _tid;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2599
  jint _depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2600
  jmethodID _method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2601
  bool _continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2602
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2603
  void set_context(jlong thread_tag, jlong tid, jint depth, jmethodID method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2604
    _thread_tag = thread_tag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2605
    _tid = tid;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2606
    _depth = depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2607
    _method = method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2608
    _continue = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2609
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2610
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2611
  inline bool stopped() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2612
    return !_continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2613
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2614
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2615
  void do_oop(oop* obj_p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2616
    // iteration has terminated
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2617
    if (stopped()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2618
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2619
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2620
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2621
    oop o = *obj_p;
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents: 48616
diff changeset
  2622
    // ignore null
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents: 48616
diff changeset
  2623
    if (o == NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2624
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2625
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2626
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2627
    // invoke the callback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2628
    _continue = CallbackInvoker::report_jni_local_root(_thread_tag, _tid, _depth, _method, o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2629
  }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  2630
  virtual void do_oop(narrowOop* obj_p) { ShouldNotReachHere(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2631
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2632
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2633
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2634
// A VM operation to iterate over objects that are reachable from
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2635
// a set of roots or an initial object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2636
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2637
// For VM_HeapWalkOperation the set of roots used is :-
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2638
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2639
// - All JNI global references
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2640
// - All inflated monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2641
// - All classes loaded by the boot class loader (or all classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2642
//     in the event that class unloading is disabled)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2643
// - All java threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2644
// - For each java thread then all locals and JNI local references
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2645
//      on the thread's execution stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2646
// - All visible/explainable objects from Universes::oops_do
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2647
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2648
class VM_HeapWalkOperation: public VM_Operation {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2649
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2650
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2651
    initial_visit_stack_size = 4000
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2652
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2653
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2654
  bool _is_advanced_heap_walk;                      // indicates FollowReferences
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2655
  JvmtiTagMap* _tag_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2656
  Handle _initial_object;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2657
  GrowableArray<oop>* _visit_stack;                 // the visit stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2658
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2659
  bool _collecting_heap_roots;                      // are we collecting roots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2660
  bool _following_object_refs;                      // are we following object references
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2661
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2662
  bool _reporting_primitive_fields;                 // optional reporting
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2663
  bool _reporting_primitive_array_values;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2664
  bool _reporting_string_values;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2665
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2666
  GrowableArray<oop>* create_visit_stack() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 13096
diff changeset
  2667
    return new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(initial_visit_stack_size, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2668
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2669
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2670
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2671
  bool is_advanced_heap_walk() const               { return _is_advanced_heap_walk; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2672
  JvmtiTagMap* tag_map() const                     { return _tag_map; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2673
  Handle initial_object() const                    { return _initial_object; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2674
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2675
  bool is_following_references() const             { return _following_object_refs; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2676
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2677
  bool is_reporting_primitive_fields()  const      { return _reporting_primitive_fields; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2678
  bool is_reporting_primitive_array_values() const { return _reporting_primitive_array_values; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2679
  bool is_reporting_string_values() const          { return _reporting_string_values; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2680
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2681
  GrowableArray<oop>* visit_stack() const          { return _visit_stack; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2682
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2683
  // iterate over the various object types
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2684
  inline bool iterate_over_array(oop o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2685
  inline bool iterate_over_type_array(oop o);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  2686
  inline bool iterate_over_class(oop o);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2687
  inline bool iterate_over_object(oop o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2688
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2689
  // root collection
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2690
  inline bool collect_simple_roots();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2691
  inline bool collect_stack_roots();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2692
  inline bool collect_stack_roots(JavaThread* java_thread, JNILocalRootsClosure* blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2693
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2694
  // visit an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2695
  inline bool visit(oop o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2696
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2697
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2698
  VM_HeapWalkOperation(JvmtiTagMap* tag_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2699
                       Handle initial_object,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2700
                       BasicHeapWalkContext callbacks,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2701
                       const void* user_data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2702
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2703
  VM_HeapWalkOperation(JvmtiTagMap* tag_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2704
                       Handle initial_object,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2705
                       AdvancedHeapWalkContext callbacks,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2706
                       const void* user_data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2707
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2708
  ~VM_HeapWalkOperation();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2709
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2710
  VMOp_Type type() const { return VMOp_HeapWalkOperation; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2711
  void doit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2712
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2713
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2714
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2715
VM_HeapWalkOperation::VM_HeapWalkOperation(JvmtiTagMap* tag_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2716
                                           Handle initial_object,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2717
                                           BasicHeapWalkContext callbacks,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2718
                                           const void* user_data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2719
  _is_advanced_heap_walk = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2720
  _tag_map = tag_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2721
  _initial_object = initial_object;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2722
  _following_object_refs = (callbacks.object_ref_callback() != NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2723
  _reporting_primitive_fields = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2724
  _reporting_primitive_array_values = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2725
  _reporting_string_values = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2726
  _visit_stack = create_visit_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2727
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2728
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2729
  CallbackInvoker::initialize_for_basic_heap_walk(tag_map, _visit_stack, user_data, callbacks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2730
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2731
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2732
VM_HeapWalkOperation::VM_HeapWalkOperation(JvmtiTagMap* tag_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2733
                                           Handle initial_object,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2734
                                           AdvancedHeapWalkContext callbacks,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2735
                                           const void* user_data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2736
  _is_advanced_heap_walk = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2737
  _tag_map = tag_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2738
  _initial_object = initial_object;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2739
  _following_object_refs = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2740
  _reporting_primitive_fields = (callbacks.primitive_field_callback() != NULL);;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2741
  _reporting_primitive_array_values = (callbacks.array_primitive_value_callback() != NULL);;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2742
  _reporting_string_values = (callbacks.string_primitive_value_callback() != NULL);;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2743
  _visit_stack = create_visit_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2744
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2745
  CallbackInvoker::initialize_for_advanced_heap_walk(tag_map, _visit_stack, user_data, callbacks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2746
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2747
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2748
VM_HeapWalkOperation::~VM_HeapWalkOperation() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2749
  if (_following_object_refs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2750
    assert(_visit_stack != NULL, "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2751
    delete _visit_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2752
    _visit_stack = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2753
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2754
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2755
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2756
// an array references its class and has a reference to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2757
// each element in the array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2758
inline bool VM_HeapWalkOperation::iterate_over_array(oop o) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2759
  objArrayOop array = objArrayOop(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2760
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2761
  // array reference to its class
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13741
diff changeset
  2762
  oop mirror = ObjArrayKlass::cast(array->klass())->java_mirror();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2763
  if (!CallbackInvoker::report_class_reference(o, mirror)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2764
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2765
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2766
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2767
  // iterate over the array and report each reference to a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2768
  // non-null element
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2769
  for (int index=0; index<array->length(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2770
    oop elem = array->obj_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2771
    if (elem == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2772
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2773
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2774
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2775
    // report the array reference o[index] = elem
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2776
    if (!CallbackInvoker::report_array_element_reference(o, elem, index)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2777
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2778
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2779
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2780
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2781
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2782
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2783
// a type array references its class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2784
inline bool VM_HeapWalkOperation::iterate_over_type_array(oop o) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  2785
  Klass* k = o->klass();
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14082
diff changeset
  2786
  oop mirror = k->java_mirror();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2787
  if (!CallbackInvoker::report_class_reference(o, mirror)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2788
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2789
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2790
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2791
  // report the array contents if required
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2792
  if (is_reporting_primitive_array_values()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2793
    if (!CallbackInvoker::report_primitive_array_values(o)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2794
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2795
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2796
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2797
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2798
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2799
22741
13fdeb7d7aad 8033289: clang: clean up unused function warning
henryjen
parents: 20282
diff changeset
  2800
#ifdef ASSERT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2801
// verify that a static oop field is in range
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  2802
static inline bool verify_static_oop(InstanceKlass* ik,
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8076
diff changeset
  2803
                                     oop mirror, int offset) {
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8076
diff changeset
  2804
  address obj_p = (address)mirror + offset;
13738
d67be49a5beb 7195833: NPG: Rename instanceClassLoaderKlass, instanceRefKlass and instanceMirrorKlass
coleenp
parents: 13728
diff changeset
  2805
  address start = (address)InstanceMirrorKlass::start_of_static_fields(mirror);
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8076
diff changeset
  2806
  address end = start + (java_lang_Class::static_oop_field_count(mirror) * heapOopSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2807
  assert(end >= start, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2808
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2809
  if (obj_p >= start && obj_p < end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2810
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2811
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2812
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2813
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2814
}
22741
13fdeb7d7aad 8033289: clang: clean up unused function warning
henryjen
parents: 20282
diff changeset
  2815
#endif // #ifdef ASSERT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2816
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2817
// a class references its super class, interfaces, class loader, ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2818
// and finally its static fields
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  2819
inline bool VM_HeapWalkOperation::iterate_over_class(oop java_class) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2820
  int i;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  2821
  Klass* klass = java_lang_Class::as_Klass(java_class);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2822
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
  2823
  if (klass->is_instance_klass()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  2824
    InstanceKlass* ik = InstanceKlass::cast(klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2825
31974
869b4f9cbb40 8131600: heapdump/JMapHeap EXCEPTION_ACCESS_VIOLATION
brutisso
parents: 30764
diff changeset
  2826
    // Ignore the class if it hasn't been initialized yet
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2827
    if (!ik->is_linked()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2828
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2829
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2830
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2831
    // get the java mirror
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2832
    oop mirror = klass->java_mirror();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2833
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2834
    // super (only if something more interesting than java.lang.Object)
51329
9c68699bebe5 8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents: 50599
diff changeset
  2835
    InstanceKlass* java_super = ik->java_super();
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 3908
diff changeset
  2836
    if (java_super != NULL && java_super != SystemDictionary::Object_klass()) {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14082
diff changeset
  2837
      oop super = java_super->java_mirror();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2838
      if (!CallbackInvoker::report_superclass_reference(mirror, super)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2839
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2840
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2841
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2842
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2843
    // class loader
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2844
    oop cl = ik->class_loader();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2845
    if (cl != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2846
      if (!CallbackInvoker::report_class_loader_reference(mirror, cl)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2847
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2848
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2849
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2850
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2851
    // protection domain
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2852
    oop pd = ik->protection_domain();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2853
    if (pd != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2854
      if (!CallbackInvoker::report_protection_domain_reference(mirror, pd)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2855
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2856
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2857
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2858
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2859
    // signers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2860
    oop signers = ik->signers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2861
    if (signers != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2862
      if (!CallbackInvoker::report_signers_reference(mirror, signers)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2863
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2864
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2865
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2866
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2867
    // references from the constant pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2868
    {
17370
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 17087
diff changeset
  2869
      ConstantPool* pool = ik->constants();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2870
      for (int i = 1; i < pool->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2871
        constantTag tag = pool->tag_at(i).value();
51665
cda49f297cb1 8209361: [AOT] Unexpected number of references for JVMTI_HEAP_REFERENCE_CONSTANT_POOL [111-->111]: 0 (expected at least 1)
dlong
parents: 51470
diff changeset
  2872
        if (tag.is_string() || tag.is_klass() || tag.is_unresolved_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2873
          oop entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2874
          if (tag.is_string()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2875
            entry = pool->resolved_string_at(i);
13976
93a075193661 8000459: assert(java_lang_String::is_instance(entry)) failure with various mlvm tests.
jiangli
parents: 13741
diff changeset
  2876
            // If the entry is non-null it is resolved.
51665
cda49f297cb1 8209361: [AOT] Unexpected number of references for JVMTI_HEAP_REFERENCE_CONSTANT_POOL [111-->111]: 0 (expected at least 1)
dlong
parents: 51470
diff changeset
  2877
            if (entry == NULL) {
cda49f297cb1 8209361: [AOT] Unexpected number of references for JVMTI_HEAP_REFERENCE_CONSTANT_POOL [111-->111]: 0 (expected at least 1)
dlong
parents: 51470
diff changeset
  2878
              continue;
cda49f297cb1 8209361: [AOT] Unexpected number of references for JVMTI_HEAP_REFERENCE_CONSTANT_POOL [111-->111]: 0 (expected at least 1)
dlong
parents: 51470
diff changeset
  2879
            }
cda49f297cb1 8209361: [AOT] Unexpected number of references for JVMTI_HEAP_REFERENCE_CONSTANT_POOL [111-->111]: 0 (expected at least 1)
dlong
parents: 51470
diff changeset
  2880
          } else if (tag.is_klass()) {
cda49f297cb1 8209361: [AOT] Unexpected number of references for JVMTI_HEAP_REFERENCE_CONSTANT_POOL [111-->111]: 0 (expected at least 1)
dlong
parents: 51470
diff changeset
  2881
            entry = pool->resolved_klass_at(i)->java_mirror();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2882
          } else {
51665
cda49f297cb1 8209361: [AOT] Unexpected number of references for JVMTI_HEAP_REFERENCE_CONSTANT_POOL [111-->111]: 0 (expected at least 1)
dlong
parents: 51470
diff changeset
  2883
            // Code generated by JIT and AOT compilers might not resolve constant
cda49f297cb1 8209361: [AOT] Unexpected number of references for JVMTI_HEAP_REFERENCE_CONSTANT_POOL [111-->111]: 0 (expected at least 1)
dlong
parents: 51470
diff changeset
  2884
            // pool entries.  Treat them as resolved if they are loaded.
cda49f297cb1 8209361: [AOT] Unexpected number of references for JVMTI_HEAP_REFERENCE_CONSTANT_POOL [111-->111]: 0 (expected at least 1)
dlong
parents: 51470
diff changeset
  2885
            assert(tag.is_unresolved_klass(), "must be");
cda49f297cb1 8209361: [AOT] Unexpected number of references for JVMTI_HEAP_REFERENCE_CONSTANT_POOL [111-->111]: 0 (expected at least 1)
dlong
parents: 51470
diff changeset
  2886
            constantPoolHandle cp(Thread::current(), pool);
cda49f297cb1 8209361: [AOT] Unexpected number of references for JVMTI_HEAP_REFERENCE_CONSTANT_POOL [111-->111]: 0 (expected at least 1)
dlong
parents: 51470
diff changeset
  2887
            Klass* klass = ConstantPool::klass_at_if_loaded(cp, i);
cda49f297cb1 8209361: [AOT] Unexpected number of references for JVMTI_HEAP_REFERENCE_CONSTANT_POOL [111-->111]: 0 (expected at least 1)
dlong
parents: 51470
diff changeset
  2888
            if (klass == NULL) {
cda49f297cb1 8209361: [AOT] Unexpected number of references for JVMTI_HEAP_REFERENCE_CONSTANT_POOL [111-->111]: 0 (expected at least 1)
dlong
parents: 51470
diff changeset
  2889
              continue;
cda49f297cb1 8209361: [AOT] Unexpected number of references for JVMTI_HEAP_REFERENCE_CONSTANT_POOL [111-->111]: 0 (expected at least 1)
dlong
parents: 51470
diff changeset
  2890
            }
cda49f297cb1 8209361: [AOT] Unexpected number of references for JVMTI_HEAP_REFERENCE_CONSTANT_POOL [111-->111]: 0 (expected at least 1)
dlong
parents: 51470
diff changeset
  2891
            entry = klass->java_mirror();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2892
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2893
          if (!CallbackInvoker::report_constant_pool_reference(mirror, entry, (jint)i)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2894
            return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2895
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2896
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2897
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2898
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2899
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2900
    // interfaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2901
    // (These will already have been reported as references from the constant pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2902
    //  but are specified by IterateOverReachableObjects and must be reported).
51329
9c68699bebe5 8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents: 50599
diff changeset
  2903
    Array<InstanceKlass*>* interfaces = ik->local_interfaces();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2904
    for (i = 0; i < interfaces->length(); i++) {
51329
9c68699bebe5 8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents: 50599
diff changeset
  2905
      oop interf = interfaces->at(i)->java_mirror();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2906
      if (interf == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2907
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2908
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2909
      if (!CallbackInvoker::report_interface_reference(mirror, interf)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2910
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2911
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2912
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2913
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2914
    // iterate over the static fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2915
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  2916
    ClassFieldMap* field_map = ClassFieldMap::create_map_of_static_fields(klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2917
    for (i=0; i<field_map->field_count(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2918
      ClassFieldDescriptor* field = field_map->field_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2919
      char type = field->field_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2920
      if (!is_primitive_field_type(type)) {
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8076
diff changeset
  2921
        oop fld_o = mirror->obj_field(field->field_offset());
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8076
diff changeset
  2922
        assert(verify_static_oop(ik, mirror, field->field_offset()), "sanity check");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2923
        if (fld_o != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2924
          int slot = field->field_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2925
          if (!CallbackInvoker::report_static_field_reference(mirror, fld_o, slot)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2926
            delete field_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2927
            return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2928
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2929
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2930
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2931
         if (is_reporting_primitive_fields()) {
8726
7bafcf0e5bfb 7029509: nightly failures after static fields in Class
never
parents: 8725
diff changeset
  2932
           address addr = (address)mirror + field->field_offset();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2933
           int slot = field->field_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2934
           if (!CallbackInvoker::report_primitive_static_field(mirror, slot, addr, type)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2935
             delete field_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2936
             return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2937
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2938
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2939
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2940
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2941
    delete field_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2942
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2943
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2944
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2945
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2946
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2947
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2948
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2949
// an object references a class and its instance fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2950
// (static fields are ignored here as we report these as
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2951
// references from the class).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2952
inline bool VM_HeapWalkOperation::iterate_over_object(oop o) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2953
  // reference to the class
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14082
diff changeset
  2954
  if (!CallbackInvoker::report_class_reference(o, o->klass()->java_mirror())) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2955
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2956
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2957
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2958
  // iterate over instance fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2959
  ClassFieldMap* field_map = JvmtiCachedClassFieldMap::get_map_of_instance_fields(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2960
  for (int i=0; i<field_map->field_count(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2961
    ClassFieldDescriptor* field = field_map->field_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2962
    char type = field->field_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2963
    if (!is_primitive_field_type(type)) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  2964
      oop fld_o = o->obj_field(field->field_offset());
11773
7c8ab49996da 7130993: nsk/jdi/ReferenceType/instances/instances004 fails with JFR: assert(ServiceUtil::visible_oop(obj))
sspitsyn
parents: 10229
diff changeset
  2965
      // ignore any objects that aren't visible to profiler
49476
1f904e305a05 8195109: ServiceUtil::visible_oop is not needed anymore
cjplummer
parents: 49364
diff changeset
  2966
      if (fld_o != NULL) {
58015
dd84de796f2c 8224815: Remove non-GC uses of CollectedHeap::is_in_reserved()
eosterlund
parents: 57812
diff changeset
  2967
        assert(Universe::heap()->is_in(fld_o), "unsafe code should not "
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  2968
               "have references to Klass* anymore");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2969
        int slot = field->field_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2970
        if (!CallbackInvoker::report_field_reference(o, fld_o, slot)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2971
          return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2972
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2973
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2974
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2975
      if (is_reporting_primitive_fields()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2976
        // primitive instance field
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2977
        address addr = (address)o + field->field_offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2978
        int slot = field->field_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2979
        if (!CallbackInvoker::report_primitive_instance_field(o, slot, addr, type)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2980
          return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2981
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2982
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2983
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2984
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2985
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2986
  // if the object is a java.lang.String
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2987
  if (is_reporting_string_values() &&
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 3908
diff changeset
  2988
      o->klass() == SystemDictionary::String_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2989
    if (!CallbackInvoker::report_string_value(o)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2990
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2991
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2992
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2993
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2994
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2995
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2996
10229
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  2997
// Collects all simple (non-stack) roots except for threads;
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  2998
// threads are handled in collect_stack_roots() as an optimization.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2999
// if there's a heap root callback provided then the callback is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3000
// invoked for each simple root.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3001
// if an object reference callback is provided then all simple
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3002
// roots are pushed onto the marking stack so that they can be
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3003
// processed later
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3004
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3005
inline bool VM_HeapWalkOperation::collect_simple_roots() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3006
  SimpleRootsClosure blk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3007
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3008
  // JNI globals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3009
  blk.set_kind(JVMTI_HEAP_REFERENCE_JNI_GLOBAL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3010
  JNIHandles::oops_do(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3011
  if (blk.stopped()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3012
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3013
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3014
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3015
  // Preloaded classes and loader from the system dictionary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3016
  blk.set_kind(JVMTI_HEAP_REFERENCE_SYSTEM_CLASS);
50297
580744d900c8 8202813: Move vm_weak processing from SystemDictionary to WeakProcessor
coleenp
parents: 49982
diff changeset
  3017
  SystemDictionary::oops_do(&blk);
51470
84d3126858d5 8209738: Remove ClassLoaderDataGraph::*oops_do functions
coleenp
parents: 51334
diff changeset
  3018
  CLDToOopClosure cld_closure(&blk, false);
84d3126858d5 8209738: Remove ClassLoaderDataGraph::*oops_do functions
coleenp
parents: 51334
diff changeset
  3019
  ClassLoaderDataGraph::always_strong_cld_do(&cld_closure);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3020
  if (blk.stopped()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3021
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3022
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3023
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3024
  // Inflated monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3025
  blk.set_kind(JVMTI_HEAP_REFERENCE_MONITOR);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3026
  ObjectSynchronizer::oops_do(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3027
  if (blk.stopped()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3028
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3029
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3030
10229
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  3031
  // threads are now handled in collect_stack_roots()
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3032
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3033
  // Other kinds of roots maintained by HotSpot
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3034
  // Many of these won't be visible but others (such as instances of important
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3035
  // exceptions) will be visible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3036
  blk.set_kind(JVMTI_HEAP_REFERENCE_OTHER);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3037
  Universe::oops_do(&blk);
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54376
diff changeset
  3038
  if (blk.stopped()) {
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54376
diff changeset
  3039
    return false;
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54376
diff changeset
  3040
  }
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 54376
diff changeset
  3041
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3042
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3043
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3044
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3045
// Walk the stack of a given thread and find all references (locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3046
// and JNI calls) and report these as stack references
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3047
inline bool VM_HeapWalkOperation::collect_stack_roots(JavaThread* java_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3048
                                                      JNILocalRootsClosure* blk)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3049
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3050
  oop threadObj = java_thread->threadObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3051
  assert(threadObj != NULL, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3052
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3053
  // only need to get the thread's tag once per thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3054
  jlong thread_tag = tag_for(_tag_map, threadObj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3055
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3056
  // also need the thread id
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3057
  jlong tid = java_lang_Thread::thread_id(threadObj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3058
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3059
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3060
  if (java_thread->has_last_Java_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3061
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3062
    // vframes are resource allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3063
    Thread* current_thread = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3064
    ResourceMark rm(current_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3065
    HandleMark hm(current_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3066
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3067
    RegisterMap reg_map(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3068
    frame f = java_thread->last_frame();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3069
    vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3070
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3071
    bool is_top_frame = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3072
    int depth = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3073
    frame* last_entry_frame = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3074
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3075
    while (vf != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3076
      if (vf->is_java_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3077
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3078
        // java frame (interpreted, compiled, ...)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3079
        javaVFrame *jvf = javaVFrame::cast(vf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3080
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3081
        // the jmethodID
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3082
        jmethodID method = jvf->method()->jmethod_id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3083
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3084
        if (!(jvf->method()->is_native())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3085
          jlocation bci = (jlocation)jvf->bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3086
          StackValueCollection* locals = jvf->locals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3087
          for (int slot=0; slot<locals->size(); slot++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3088
            if (locals->at(slot)->type() == T_OBJECT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3089
              oop o = locals->obj_at(slot)();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3090
              if (o == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3091
                continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3092
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3093
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3094
              // stack reference
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3095
              if (!CallbackInvoker::report_stack_ref_root(thread_tag, tid, depth, method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3096
                                                   bci, slot, o)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3097
                return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3098
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3099
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3100
          }
22895
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3101
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3102
          StackValueCollection* exprs = jvf->expressions();
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3103
          for (int index=0; index < exprs->size(); index++) {
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3104
            if (exprs->at(index)->type() == T_OBJECT) {
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3105
              oop o = exprs->obj_at(index)();
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3106
              if (o == NULL) {
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3107
                continue;
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3108
              }
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3109
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3110
              // stack reference
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3111
              if (!CallbackInvoker::report_stack_ref_root(thread_tag, tid, depth, method,
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3112
                                                   bci, locals->size() + index, o)) {
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3113
                return false;
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3114
              }
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3115
            }
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3116
          }
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 22741
diff changeset
  3117
40662
6e951c9e7318 8038797: JVMTI FollowReferences does not report roots reachable from nmethods
coleenp
parents: 37993
diff changeset
  3118
          // Follow oops from compiled nmethod
6e951c9e7318 8038797: JVMTI FollowReferences does not report roots reachable from nmethods
coleenp
parents: 37993
diff changeset
  3119
          if (jvf->cb() != NULL && jvf->cb()->is_nmethod()) {
6e951c9e7318 8038797: JVMTI FollowReferences does not report roots reachable from nmethods
coleenp
parents: 37993
diff changeset
  3120
            blk->set_context(thread_tag, tid, depth, method);
6e951c9e7318 8038797: JVMTI FollowReferences does not report roots reachable from nmethods
coleenp
parents: 37993
diff changeset
  3121
            jvf->cb()->as_nmethod()->oops_do(blk);
6e951c9e7318 8038797: JVMTI FollowReferences does not report roots reachable from nmethods
coleenp
parents: 37993
diff changeset
  3122
          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3123
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3124
          blk->set_context(thread_tag, tid, depth, method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3125
          if (is_top_frame) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3126
            // JNI locals for the top frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3127
            java_thread->active_handles()->oops_do(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3128
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3129
            if (last_entry_frame != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3130
              // JNI locals for the entry frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3131
              assert(last_entry_frame->is_entry_frame(), "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3132
              last_entry_frame->entry_frame_call_wrapper()->handles()->oops_do(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3133
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3134
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3135
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3136
        last_entry_frame = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3137
        depth++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3138
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3139
        // externalVFrame - for an entry frame then we report the JNI locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3140
        // when we find the corresponding javaVFrame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3141
        frame* fr = vf->frame_pointer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3142
        assert(fr != NULL, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3143
        if (fr->is_entry_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3144
          last_entry_frame = fr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3145
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3146
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3147
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3148
      vf = vf->sender();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3149
      is_top_frame = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3150
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3151
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3152
    // no last java frame but there may be JNI locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3153
    blk->set_context(thread_tag, tid, 0, (jmethodID)NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3154
    java_thread->active_handles()->oops_do(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3155
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3156
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3157
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3158
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3159
10229
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  3160
// Collects the simple roots for all threads and collects all
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  3161
// stack roots - for each thread it walks the execution
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3162
// stack to find all references and local JNI refs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3163
inline bool VM_HeapWalkOperation::collect_stack_roots() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3164
  JNILocalRootsClosure blk;
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47765
diff changeset
  3165
  for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3166
    oop threadObj = thread->threadObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3167
    if (threadObj != NULL && !thread->is_exiting() && !thread->is_hidden_from_external_view()) {
10229
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  3168
      // Collect the simple root for this thread before we
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  3169
      // collect its stack roots
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  3170
      if (!CallbackInvoker::report_simple_root(JVMTI_HEAP_REFERENCE_THREAD,
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  3171
                                               threadObj)) {
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  3172
        return false;
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  3173
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3174
      if (!collect_stack_roots(thread, &blk)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3175
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3176
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3177
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3178
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3179
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3181
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3182
// visit an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3183
// first mark the object as visited
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3184
// second get all the outbound references from this object (in other words, all
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3185
// the objects referenced by this object).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3186
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3187
bool VM_HeapWalkOperation::visit(oop o) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3188
  // mark object as visited
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3189
  assert(!ObjectMarker::visited(o), "can't visit same object more than once");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3190
  ObjectMarker::mark(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3191
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3192
  // instance
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3193
  if (o->is_instance()) {
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 3908
diff changeset
  3194
    if (o->klass() == SystemDictionary::Class_klass()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  3195
      if (!java_lang_Class::is_primitive(o)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3196
        // a java.lang.Class
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  3197
        return iterate_over_class(o);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3198
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3199
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3200
      return iterate_over_object(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3201
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3202
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3203
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3204
  // object array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3205
  if (o->is_objArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3206
    return iterate_over_array(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3207
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3208
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3209
  // type array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3210
  if (o->is_typeArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3211
    return iterate_over_type_array(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3212
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3213
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3214
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3215
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3216
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3217
void VM_HeapWalkOperation::doit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3218
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3219
  ObjectMarkerController marker;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3220
  ClassFieldMapCacheMark cm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3221
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3222
  assert(visit_stack()->is_empty(), "visit stack must be empty");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3223
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3224
  // the heap walk starts with an initial object or the heap roots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3225
  if (initial_object().is_null()) {
10228
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  3226
    // If either collect_stack_roots() or collect_simple_roots()
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  3227
    // returns false at this point, then there are no mark bits
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  3228
    // to reset.
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  3229
    ObjectMarker::set_needs_reset(false);
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  3230
10229
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  3231
    // Calling collect_stack_roots() before collect_simple_roots()
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  3232
    // can result in a big performance boost for an agent that is
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  3233
    // focused on analyzing references in the thread stacks.
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  3234
    if (!collect_stack_roots()) return;
7b358d5def21 6951623: 3/3 possible performance problems in FollowReferences() and GetObjectsWithTags()
dcubed
parents: 10228
diff changeset
  3235
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3236
    if (!collect_simple_roots()) return;
10228
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  3237
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  3238
    // no early return so enable heap traversal to reset the mark bits
e5e1539de725 7043987: 3/3 JVMTI FollowReferences is slow
dcubed
parents: 9630
diff changeset
  3239
    ObjectMarker::set_needs_reset(true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3240
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3241
    visit_stack()->push(initial_object()());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3242
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3243
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3244
  // object references required
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3245
  if (is_following_references()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3246
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3247
    // visit each object until all reachable objects have been
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3248
    // visited or the callback asked to terminate the iteration.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3249
    while (!visit_stack()->is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3250
      oop o = visit_stack()->pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3251
      if (!ObjectMarker::visited(o)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3252
        if (!visit(o)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3253
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3254
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3255
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3256
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3257
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3258
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3259
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3260
// iterate over all objects that are reachable from a set of roots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3261
void JvmtiTagMap::iterate_over_reachable_objects(jvmtiHeapRootCallback heap_root_callback,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3262
                                                 jvmtiStackReferenceCallback stack_ref_callback,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3263
                                                 jvmtiObjectReferenceCallback object_ref_callback,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3264
                                                 const void* user_data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3265
  MutexLocker ml(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3266
  BasicHeapWalkContext context(heap_root_callback, stack_ref_callback, object_ref_callback);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3267
  VM_HeapWalkOperation op(this, Handle(), context, user_data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3268
  VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3269
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3270
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3271
// iterate over all objects that are reachable from a given object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3272
void JvmtiTagMap::iterate_over_objects_reachable_from_object(jobject object,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3273
                                                             jvmtiObjectReferenceCallback object_ref_callback,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3274
                                                             const void* user_data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3275
  oop obj = JNIHandles::resolve(object);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3276
  Handle initial_object(Thread::current(), obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3277
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3278
  MutexLocker ml(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3279
  BasicHeapWalkContext context(NULL, NULL, object_ref_callback);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3280
  VM_HeapWalkOperation op(this, initial_object, context, user_data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3281
  VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3282
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3283
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3284
// follow references from an initial object or the GC roots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3285
void JvmtiTagMap::follow_references(jint heap_filter,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 43944
diff changeset
  3286
                                    Klass* klass,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3287
                                    jobject object,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3288
                                    const jvmtiHeapCallbacks* callbacks,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3289
                                    const void* user_data)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3290
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3291
  oop obj = JNIHandles::resolve(object);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3292
  Handle initial_object(Thread::current(), obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3293
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3294
  MutexLocker ml(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3295
  AdvancedHeapWalkContext context(heap_filter, klass, callbacks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3296
  VM_HeapWalkOperation op(this, initial_object, context, user_data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3297
  VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3298
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3299
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3300
32817
acc2744fd84b 8136627: Backout JDK-8133818 Additional number of processed references printed with -XX:+PrintReferenceGC after JDK-8047125
kbarrett
parents: 32607
diff changeset
  3301
void JvmtiTagMap::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f) {
7916
84e5b29decb0 7012493: 2/2 6849574/Test.java fails with Internal Error (src/share/vm/prims/jvmtiTagMap.cpp:3294)
dcubed
parents: 7896
diff changeset
  3302
  // No locks during VM bring-up (0 threads) and no safepoints after main
84e5b29decb0 7012493: 2/2 6849574/Test.java fails with Internal Error (src/share/vm/prims/jvmtiTagMap.cpp:3294)
dcubed
parents: 7896
diff changeset
  3303
  // thread creation and before VMThread creation (1 thread); initial GC
84e5b29decb0 7012493: 2/2 6849574/Test.java fails with Internal Error (src/share/vm/prims/jvmtiTagMap.cpp:3294)
dcubed
parents: 7896
diff changeset
  3304
  // verification can happen in that window which gets to here.
84e5b29decb0 7012493: 2/2 6849574/Test.java fails with Internal Error (src/share/vm/prims/jvmtiTagMap.cpp:3294)
dcubed
parents: 7896
diff changeset
  3305
  assert(Threads::number_of_threads() <= 1 ||
84e5b29decb0 7012493: 2/2 6849574/Test.java fails with Internal Error (src/share/vm/prims/jvmtiTagMap.cpp:3294)
dcubed
parents: 7896
diff changeset
  3306
         SafepointSynchronize::is_at_safepoint(),
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3307
         "must be executed at a safepoint");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3308
  if (JvmtiEnv::environments_might_exist()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3309
    JvmtiEnvIterator it;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3310
    for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) {
54690
7ab4310ed472 8223227: Rename acquire_tag_map() to tag_map_acquire() in jvmtiEnvBase
manc
parents: 54674
diff changeset
  3311
      JvmtiTagMap* tag_map = env->tag_map_acquire();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3312
      if (tag_map != NULL && !tag_map->is_empty()) {
32817
acc2744fd84b 8136627: Backout JDK-8133818 Additional number of processed references printed with -XX:+PrintReferenceGC after JDK-8047125
kbarrett
parents: 32607
diff changeset
  3313
        tag_map->do_weak_oops(is_alive, f);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3314
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3315
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3316
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3317
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3318
32817
acc2744fd84b 8136627: Backout JDK-8133818 Additional number of processed references printed with -XX:+PrintReferenceGC after JDK-8047125
kbarrett
parents: 32607
diff changeset
  3319
void JvmtiTagMap::do_weak_oops(BoolObjectClosure* is_alive, OopClosure* f) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3320
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3321
  // does this environment have the OBJECT_FREE event enabled
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3322
  bool post_object_free = env()->is_enabled(JVMTI_EVENT_OBJECT_FREE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3323
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3324
  // counters used for trace message
32817
acc2744fd84b 8136627: Backout JDK-8133818 Additional number of processed references printed with -XX:+PrintReferenceGC after JDK-8047125
kbarrett
parents: 32607
diff changeset
  3325
  int freed = 0;
acc2744fd84b 8136627: Backout JDK-8133818 Additional number of processed references printed with -XX:+PrintReferenceGC after JDK-8047125
kbarrett
parents: 32607
diff changeset
  3326
  int moved = 0;
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3327
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3328
  JvmtiTagHashmap* hashmap = this->hashmap();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3329
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3330
  // reenable sizing (if disabled)
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3331
  hashmap->set_resizing_enabled(true);
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3332
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3333
  // if the hashmap is empty then we can skip it
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3334
  if (hashmap->_entry_count == 0) {
32817
acc2744fd84b 8136627: Backout JDK-8133818 Additional number of processed references printed with -XX:+PrintReferenceGC after JDK-8047125
kbarrett
parents: 32607
diff changeset
  3335
    return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3336
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3337
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3338
  // now iterate through each entry in the table
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3339
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3340
  JvmtiTagHashmapEntry** table = hashmap->table();
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3341
  int size = hashmap->size();
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3342
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3343
  JvmtiTagHashmapEntry* delayed_add = NULL;
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3344
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3345
  for (int pos = 0; pos < size; ++pos) {
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3346
    JvmtiTagHashmapEntry* entry = table[pos];
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3347
    JvmtiTagHashmapEntry* prev = NULL;
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3348
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3349
    while (entry != NULL) {
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3350
      JvmtiTagHashmapEntry* next = entry->next();
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3351
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3352
      // has object been GC'ed
48616
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
  3353
      if (!is_alive->do_object_b(entry->object_peek())) {
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3354
        // grab the tag
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3355
        jlong tag = entry->tag();
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3356
        guarantee(tag != 0, "checking");
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3357
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3358
        // remove GC'ed entry from hashmap and return the
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3359
        // entry to the free list
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3360
        hashmap->remove(prev, pos, entry);
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3361
        destroy_entry(entry);
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3362
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3363
        // post the event to the profiler
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3364
        if (post_object_free) {
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3365
          JvmtiExport::post_object_free(env(), tag);
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3366
        }
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3367
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3368
        ++freed;
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3369
      } else {
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3370
        f->do_oop(entry->object_addr());
48616
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
  3371
        oop new_oop = entry->object_peek();
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3372
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3373
        // if the object has moved then re-hash it and move its
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3374
        // entry to its new location.
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3375
        unsigned int new_pos = JvmtiTagHashmap::hash(new_oop, size);
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3376
        if (new_pos != (unsigned int)pos) {
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3377
          if (prev == NULL) {
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3378
            table[pos] = next;
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3379
          } else {
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3380
            prev->set_next(next);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3381
          }
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3382
          if (new_pos < (unsigned int)pos) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3383
            entry->set_next(table[new_pos]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3384
            table[new_pos] = entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3385
          } else {
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3386
            // Delay adding this entry to it's new position as we'd end up
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3387
            // hitting it again during this iteration.
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3388
            entry->set_next(delayed_add);
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3389
            delayed_add = entry;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3390
          }
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3391
          moved++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3392
        } else {
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3393
          // object didn't move
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3394
          prev = entry;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3395
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3396
      }
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3397
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3398
      entry = next;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3399
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3400
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3401
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3402
  // Re-add all the entries which were kept aside
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3403
  while (delayed_add != NULL) {
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3404
    JvmtiTagHashmapEntry* next = delayed_add->next();
48616
80239a242d34 8191894: Refactor weak references in JvmtiTagHashmap to use the Access API
eosterlund
parents: 48105
diff changeset
  3405
    unsigned int pos = JvmtiTagHashmap::hash(delayed_add->object_peek(), size);
7896
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3406
    delayed_add->set_next(table[pos]);
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3407
    table[pos] = delayed_add;
08aadd7aa3ee 6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
kamg
parents: 7397
diff changeset
  3408
    delayed_add = next;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3409
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3410
37993
e446184da25e 8154059: JVMTI ObjectTagging to UL
rehn
parents: 37248
diff changeset
  3411
  log_debug(jvmti, objecttagging)("(%d->%d, %d freed, %d total moves)",
e446184da25e 8154059: JVMTI ObjectTagging to UL
rehn
parents: 37248
diff changeset
  3412
                                  hashmap->_entry_count + freed, hashmap->_entry_count, freed, moved);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3413
}