src/share/vm/jfr/leakprofiler/checkpoint/objectSampleWriter.cpp

changeset 9885
8e875c964f41
parent 9858
b985cbb00e68
     1.1 --- a/src/share/vm/jfr/leakprofiler/checkpoint/objectSampleWriter.cpp	Fri Sep 27 13:23:32 2019 +0800
     1.2 +++ b/src/share/vm/jfr/leakprofiler/checkpoint/objectSampleWriter.cpp	Wed Oct 09 16:11:58 2019 +0800
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -350,7 +350,7 @@
    1.11    return 1;
    1.12  }
    1.13  
    1.14 -static traceid get_root_description_info_id(const Edge& edge, traceid id) {
    1.15 +static traceid get_gc_root_description_info_id(const Edge& edge, traceid id) {
    1.16    assert(edge.is_root(), "invariant");
    1.17    if (EdgeUtils::is_leak_edge(edge)) {
    1.18      return 0;
    1.19 @@ -518,7 +518,7 @@
    1.20    }
    1.21  }
    1.22  
    1.23 -static void add_old_object_sample_info(const Edge* current, traceid id) {
    1.24 +static void add_old_object_sample_info(const StoredEdge* current, traceid id) {
    1.25    assert(current != NULL, "invariant");
    1.26    if (sample_infos == NULL) {
    1.27      sample_infos = new SampleInfo();
    1.28 @@ -528,11 +528,11 @@
    1.29    assert(oosi != NULL, "invariant");
    1.30    oosi->_id = id;
    1.31    oosi->_data._object = current->pointee();
    1.32 -  oosi->_data._reference_id = current->is_root() ? (traceid)0 : id;
    1.33 +  oosi->_data._reference_id = current->parent() == NULL ? (traceid)0 : id;
    1.34    sample_infos->store(oosi);
    1.35  }
    1.36  
    1.37 -static void add_reference_info(const RoutableEdge* current, traceid id, traceid parent_id) {
    1.38 +static void add_reference_info(const StoredEdge* current, traceid id, traceid parent_id) {
    1.39    assert(current != NULL, "invariant");
    1.40    if (ref_infos == NULL) {
    1.41      ref_infos = new RefInfo();
    1.42 @@ -544,37 +544,43 @@
    1.43  
    1.44    ri->_id = id;
    1.45    ri->_data._array_info_id =  !current->is_skip_edge() ? get_array_info_id(*current, id) : 0;
    1.46 -  ri->_data._field_info_id = ri->_data._array_info_id == 0 && !current->is_skip_edge() ?
    1.47 -                               get_field_info_id(*current) : (traceid)0;
    1.48 +  ri->_data._field_info_id = ri->_data._array_info_id == 0 && !current->is_skip_edge() ? get_field_info_id(*current) : (traceid)0;
    1.49    ri->_data._old_object_sample_id = parent_id;
    1.50    ri->_data._skip = current->skip_length();
    1.51    ref_infos->store(ri);
    1.52  }
    1.53  
    1.54 -static traceid add_root_info(const Edge* root, traceid id) {
    1.55 -  assert(root != NULL, "invariant");
    1.56 -  assert(root->is_root(), "invariant");
    1.57 -  return get_root_description_info_id(*root, id);
    1.58 +static bool is_gc_root(const StoredEdge* current) {
    1.59 +  assert(current != NULL, "invariant");
    1.60 +  return current->parent() == NULL && current->gc_root_id() != 0;
    1.61  }
    1.62  
    1.63 -void ObjectSampleWriter::write(const RoutableEdge* edge) {
    1.64 +static traceid add_gc_root_info(const StoredEdge* root, traceid id) {
    1.65 +  assert(root != NULL, "invariant");
    1.66 +  assert(is_gc_root(root), "invariant");
    1.67 +  return get_gc_root_description_info_id(*root, id);
    1.68 +}
    1.69 +
    1.70 +void ObjectSampleWriter::write(const StoredEdge* edge) {
    1.71    assert(edge != NULL, "invariant");
    1.72    const traceid id = _store->get_id(edge);
    1.73    add_old_object_sample_info(edge, id);
    1.74 -  const RoutableEdge* parent = edge->logical_parent();
    1.75 +  const StoredEdge* const parent = edge->parent();
    1.76    if (parent != NULL) {
    1.77      add_reference_info(edge, id, _store->get_id(parent));
    1.78    } else {
    1.79 -    assert(edge->is_root(), "invariant");
    1.80 -    add_root_info(edge, id);
    1.81 +    if (is_gc_root(edge)) {
    1.82 +      assert(edge->gc_root_id() == id, "invariant");
    1.83 +      add_gc_root_info(edge, id);
    1.84 +    }
    1.85    }
    1.86  }
    1.87  
    1.88 -ObjectSampleWriter::ObjectSampleWriter(JfrCheckpointWriter& writer, const EdgeStore* store) :
    1.89 +ObjectSampleWriter::ObjectSampleWriter(JfrCheckpointWriter& writer, EdgeStore* store) :
    1.90    _writer(writer),
    1.91    _store(store) {
    1.92    assert(store != NULL, "invariant");
    1.93 -  assert(store->number_of_entries() > 0, "invariant");
    1.94 +  assert(!store->is_empty(), "invariant");
    1.95    sample_infos = NULL;
    1.96    ref_infos = NULL;
    1.97    array_infos = NULL;
    1.98 @@ -590,26 +596,7 @@
    1.99    write_root_descriptors(_writer);
   1.100  }
   1.101  
   1.102 -void ObjectSampleWriter::write_chain(const RoutableEdge& edge) {
   1.103 -  assert(EdgeUtils::is_leak_edge(edge), "invariant");
   1.104 -  if (edge.processed()) {
   1.105 -    return;
   1.106 -  }
   1.107 -  EdgeUtils::collapse_chain(edge);
   1.108 -  const RoutableEdge* current = &edge;
   1.109 -  while (current != NULL) {
   1.110 -    if (current->processed()) {
   1.111 -      return;
   1.112 -    }
   1.113 -    write(current);
   1.114 -    current->set_processed();
   1.115 -    current = current->logical_parent();
   1.116 -  }
   1.117 -}
   1.118 -
   1.119 -bool ObjectSampleWriter::operator()(const RoutableEdge& edge) {
   1.120 -  if (EdgeUtils::is_leak_edge(edge)) {
   1.121 -    write_chain(edge);
   1.122 -  }
   1.123 +bool ObjectSampleWriter::operator()(StoredEdge& e) {
   1.124 +  write(&e);
   1.125    return true;
   1.126  }

mercurial