src/hotspot/share/jfr/leakprofiler/chains/edgeUtils.cpp
author stefank
Tue, 06 Aug 2019 10:48:21 +0200
changeset 57777 90ead0febf56
parent 55571 49102ba8cf14
child 58679 9c3209ff7550
child 59056 15936b142f86
permissions -rw-r--r--
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier Reviewed-by: rkennke, coleenp, kbarrett, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     1
/*
55571
49102ba8cf14 8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents: 50113
diff changeset
     2
 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     4
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     8
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    13
 * accompanied this code).
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    14
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    18
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    21
 * questions.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    22
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    23
 */
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    24
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    25
#include "precompiled.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    26
#include "classfile/javaClasses.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    27
#include "jfr/leakprofiler/chains/edge.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    28
#include "jfr/leakprofiler/chains/edgeStore.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    29
#include "jfr/leakprofiler/chains/edgeUtils.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    30
#include "jfr/leakprofiler/utilities/unifiedOop.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    31
#include "oops/fieldStreams.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    32
#include "oops/instanceKlass.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    33
#include "oops/objArrayOop.inline.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    34
#include "oops/oopsHierarchy.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    35
#include "runtime/handles.inline.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    36
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    37
bool EdgeUtils::is_leak_edge(const Edge& edge) {
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 55571
diff changeset
    38
  return (const Edge*)edge.pointee()->mark().to_pointer() == &edge;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    39
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    40
55571
49102ba8cf14 8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents: 50113
diff changeset
    41
static int field_offset(const StoredEdge& edge) {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    42
  assert(!edge.is_root(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    43
  const oop ref_owner = edge.reference_owner();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    44
  assert(ref_owner != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    45
  const oop* reference = UnifiedOop::decode(edge.reference());
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    46
  assert(reference != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    47
  assert(!UnifiedOop::is_narrow(reference), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    48
  assert(!ref_owner->is_array(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    49
  assert(ref_owner->is_instance(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    50
  const int offset = (int)pointer_delta(reference, ref_owner, sizeof(char));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    51
  assert(offset < (ref_owner->size() * HeapWordSize), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    52
  return offset;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    53
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    54
55571
49102ba8cf14 8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents: 50113
diff changeset
    55
static const InstanceKlass* field_type(const StoredEdge& edge) {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    56
  assert(!edge.is_root() || !EdgeUtils::is_array_element(edge), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    57
  return (const InstanceKlass*)edge.reference_owner_klass();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    58
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    59
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    60
const Symbol* EdgeUtils::field_name_symbol(const Edge& edge) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    61
  assert(!edge.is_root(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    62
  assert(!is_array_element(edge), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    63
  const int offset = field_offset(edge);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    64
  const InstanceKlass* ik = field_type(edge);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    65
  while (ik != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    66
    JavaFieldStream jfs(ik);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    67
    while (!jfs.done()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    68
      if (offset == jfs.offset()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    69
        return jfs.name();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    70
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    71
      jfs.next();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    72
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    73
    ik = (InstanceKlass*)ik->super();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    74
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    75
  return NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    76
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    77
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    78
jshort EdgeUtils::field_modifiers(const Edge& edge) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    79
  const int offset = field_offset(edge);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    80
  const InstanceKlass* ik = field_type(edge);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    81
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    82
  while (ik != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    83
    JavaFieldStream jfs(ik);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    84
    while (!jfs.done()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    85
      if (offset == jfs.offset()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    86
        return jfs.access_flags().as_short();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    87
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    88
      jfs.next();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    89
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    90
    ik = (InstanceKlass*)ik->super();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    91
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    92
  return 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    93
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    94
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    95
bool EdgeUtils::is_array_element(const Edge& edge) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    96
  assert(!edge.is_root(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    97
  const oop ref_owner = edge.reference_owner();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    98
  assert(ref_owner != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    99
  return ref_owner->is_objArray();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   100
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   101
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   102
static int array_offset(const Edge& edge) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   103
  assert(!edge.is_root(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   104
  const oop ref_owner = edge.reference_owner();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   105
  assert(ref_owner != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   106
  const oop* reference = UnifiedOop::decode(edge.reference());
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   107
  assert(reference != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   108
  assert(!UnifiedOop::is_narrow(reference), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   109
  assert(ref_owner->is_array(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   110
  const objArrayOop ref_owner_array = static_cast<const objArrayOop>(ref_owner);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   111
  const int offset = (int)pointer_delta(reference, ref_owner_array->base(), heapOopSize);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   112
  assert(offset >= 0 && offset < ref_owner_array->length(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   113
  return offset;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   114
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   115
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   116
int EdgeUtils::array_index(const Edge& edge) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   117
  return is_array_element(edge) ? array_offset(edge) : 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   118
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   119
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   120
int EdgeUtils::array_size(const Edge& edge) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   121
  if (is_array_element(edge)) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   122
    const oop ref_owner = edge.reference_owner();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   123
    assert(ref_owner != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   124
    assert(ref_owner->is_objArray(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   125
    return ((objArrayOop)(ref_owner))->length();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   126
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   127
  return 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   128
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   129
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   130
const Edge* EdgeUtils::root(const Edge& edge) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   131
  const Edge* current = &edge;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   132
  const Edge* parent = current->parent();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   133
  while (parent != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   134
    current = parent;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   135
    parent = current->parent();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   136
  }
55571
49102ba8cf14 8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents: 50113
diff changeset
   137
  assert(current != NULL, "invariant");
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   138
  return current;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   139
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   140
55571
49102ba8cf14 8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents: 50113
diff changeset
   141
const Edge* EdgeUtils::ancestor(const Edge& edge, size_t distance) {
49102ba8cf14 8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents: 50113
diff changeset
   142
  const Edge* current = &edge;
49102ba8cf14 8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents: 50113
diff changeset
   143
  const Edge* parent = current->parent();
49102ba8cf14 8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents: 50113
diff changeset
   144
  size_t seek = 0;
49102ba8cf14 8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents: 50113
diff changeset
   145
  while (parent != NULL && seek != distance) {
49102ba8cf14 8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents: 50113
diff changeset
   146
    seek++;
49102ba8cf14 8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents: 50113
diff changeset
   147
    current = parent;
49102ba8cf14 8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents: 50113
diff changeset
   148
    parent = parent->parent();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   149
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   150
  return current;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   151
}