src/hotspot/share/jfr/leakprofiler/sampling/objectSampler.cpp
author mgronlun
Thu, 29 Aug 2019 12:53:05 +0200
branchJEP-349-branch
changeset 57934 9c150f2b1fea
parent 57902 f6502e486572
child 57983 a57907813a83
permissions -rw-r--r--
optimizations for old object sample metadata
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     1
/*
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
     2
 * Copyright (c) 2017, 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
 */
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    24
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    25
#include "precompiled.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    26
#include "jfr/jfrEvents.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    27
#include "jfr/leakprofiler/sampling/objectSample.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    28
#include "jfr/leakprofiler/sampling/objectSampler.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    29
#include "jfr/leakprofiler/sampling/sampleList.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    30
#include "jfr/leakprofiler/sampling/samplePriorityQueue.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    31
#include "jfr/recorder/jfrEventSetting.inline.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    32
#include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    33
#include "jfr/recorder/stacktrace/jfrStackTraceRepository.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    34
#include "jfr/support/jfrThreadLocal.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    35
#include "jfr/utilities/jfrTryLock.hpp"
50880
e1117321adaf 8197425: Liveset information for Old Object sample event
egahlin
parents: 50113
diff changeset
    36
#include "logging/log.hpp"
e1117321adaf 8197425: Liveset information for Old Object sample event
egahlin
parents: 50113
diff changeset
    37
#include "memory/universe.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    38
#include "oops/oop.inline.hpp"
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    39
#include "runtime/atomic.hpp"
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    40
#include "runtime/orderAccess.hpp"
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    41
#include "runtime/safepoint.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    42
#include "runtime/thread.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    43
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    44
static ObjectSampler* _instance = NULL;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    45
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    46
static ObjectSampler& instance() {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    47
  assert(_instance != NULL, "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    48
  return *_instance;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    49
}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    50
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    51
ObjectSampler::ObjectSampler(size_t size) :
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    52
  _priority_queue(new SamplePriorityQueue(size)),
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    53
  _list(new SampleList(size)),
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    54
  _last_sweep(JfrTicks::now()),
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    55
  _total_allocated(0),
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    56
  _threshold(0),
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    57
  _size(size),
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    58
  _dead_samples(false) {}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    59
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    60
ObjectSampler::~ObjectSampler() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    61
  delete _priority_queue;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    62
  _priority_queue = NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    63
  delete _list;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    64
  _list = NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    65
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    66
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    67
bool ObjectSampler::create(size_t size) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    68
  assert(SafepointSynchronize::is_at_safepoint(), "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    69
  assert(_instance == NULL, "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    70
  _instance = new ObjectSampler(size);
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    71
  return _instance != NULL;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    72
}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    73
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    74
bool ObjectSampler::is_created() {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    75
  return _instance != NULL;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    76
}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    77
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    78
ObjectSampler* ObjectSampler::sampler() {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    79
  assert(is_created(), "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    80
  return _instance;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    81
}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    82
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    83
void ObjectSampler::destroy() {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    84
  assert(SafepointSynchronize::is_at_safepoint(), "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    85
  if (_instance != NULL) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    86
    ObjectSampler* const sampler = _instance;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    87
    _instance = NULL;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    88
    delete sampler;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    89
  }
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    90
}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    91
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    92
static volatile int _lock = 0;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    93
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    94
ObjectSampler* ObjectSampler::acquire() {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    95
  assert(is_created(), "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    96
  while (Atomic::cmpxchg(1, &_lock, 0) == 1) {}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    97
  return _instance;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    98
}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
    99
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   100
void ObjectSampler::release() {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   101
  assert(is_created(), "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   102
  OrderAccess::fence();
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   103
  _lock = 0;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   104
}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   105
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   106
static traceid get_thread_id(JavaThread* thread) {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   107
  assert(thread != NULL, "invariant");
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   108
  if (thread->threadObj() == NULL) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   109
    return 0;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   110
  }
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   111
  const JfrThreadLocal* const tl = thread->jfr_thread_local();
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   112
  assert(tl != NULL, "invariant");
57934
9c150f2b1fea optimizations for old object sample metadata
mgronlun
parents: 57902
diff changeset
   113
  if (tl->is_excluded()) {
9c150f2b1fea optimizations for old object sample metadata
mgronlun
parents: 57902
diff changeset
   114
    return 0;
9c150f2b1fea optimizations for old object sample metadata
mgronlun
parents: 57902
diff changeset
   115
  }
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   116
  if (!tl->has_thread_checkpoint()) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   117
    JfrCheckpointManager::create_thread_checkpoint(thread);
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   118
  }
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   119
  assert(tl->has_thread_checkpoint(), "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   120
  return tl->thread_id();
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   121
}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   122
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   123
static void record_stacktrace(JavaThread* thread) {
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   124
  assert(thread != NULL, "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   125
  if (JfrEventSetting::has_stacktrace(EventOldObjectSample::eventId)) {
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   126
    JfrStackTraceRepository::record_and_cache(thread);
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   127
  }
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   128
}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   129
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   130
void ObjectSampler::sample(HeapWord* obj, size_t allocated, JavaThread* thread) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   131
  assert(thread != NULL, "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   132
  assert(is_created(), "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   133
  const traceid thread_id = get_thread_id(thread);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   134
  if (thread_id == 0) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   135
    return;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   136
  }
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   137
  record_stacktrace(thread);
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   138
  // try enter critical section
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   139
  JfrTryLock tryLock(&_lock);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   140
  if (!tryLock.has_lock()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   141
    log_trace(jfr, oldobject, sampling)("Skipping old object sample due to lock contention");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   142
    return;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   143
  }
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   144
  instance().add(obj, allocated, thread_id, thread);
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   145
}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   146
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   147
void ObjectSampler::add(HeapWord* obj, size_t allocated, traceid thread_id, JavaThread* thread) {
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   148
  assert(obj != NULL, "invariant");
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   149
  assert(thread_id != 0, "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   150
  assert(thread != NULL, "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   151
  assert(thread->jfr_thread_local()->has_thread_checkpoint(), "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   152
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   153
  if (_dead_samples) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   154
    scavenge();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   155
    assert(!_dead_samples, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   156
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   157
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   158
  _total_allocated += allocated;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   159
  const size_t span = _total_allocated - _priority_queue->total();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   160
  ObjectSample* sample;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   161
  if ((size_t)_priority_queue->count() == _size) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   162
    assert(_list->count() == _size, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   163
    const ObjectSample* peek = _priority_queue->peek();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   164
    if (peek->span() > span) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   165
      // quick reject, will not fit
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   166
      return;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   167
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   168
    sample = _list->reuse(_priority_queue->pop());
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   169
  } else {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   170
    sample = _list->get();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   171
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   172
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   173
  assert(sample != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   174
  sample->set_thread_id(thread_id);
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   175
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   176
  const JfrThreadLocal* const tl = thread->jfr_thread_local();
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   177
  sample->set_thread_checkpoint(tl->thread_checkpoint());
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   178
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   179
  const unsigned int stacktrace_hash = tl->cached_stack_trace_hash();
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   180
  if (stacktrace_hash != 0) {
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   181
    sample->set_stack_trace_id(tl->cached_stack_trace_id());
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   182
    sample->set_stack_trace_hash(stacktrace_hash);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   183
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   184
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   185
  sample->set_span(allocated);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   186
  sample->set_object((oop)obj);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   187
  sample->set_allocated(allocated);
50880
e1117321adaf 8197425: Liveset information for Old Object sample event
egahlin
parents: 50113
diff changeset
   188
  sample->set_allocation_time(JfrTicks::now());
e1117321adaf 8197425: Liveset information for Old Object sample event
egahlin
parents: 50113
diff changeset
   189
  sample->set_heap_used_at_last_gc(Universe::get_heap_used_at_last_gc());
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   190
  _priority_queue->push(sample);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   191
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   192
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   193
void ObjectSampler::scavenge() {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   194
  ObjectSample* current = _list->last();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   195
  while (current != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   196
    ObjectSample* next = current->next();
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   197
    if (current->is_dead()) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   198
      remove_dead(current);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   199
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   200
    current = next;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   201
  }
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   202
  _dead_samples = false;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   203
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   204
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   205
void ObjectSampler::remove_dead(ObjectSample* sample) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   206
  assert(sample != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   207
  assert(sample->is_dead(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   208
  ObjectSample* const previous = sample->prev();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   209
  // push span on to previous
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   210
  if (previous != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   211
    _priority_queue->remove(previous);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   212
    previous->add_span(sample->span());
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   213
    _priority_queue->push(previous);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   214
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   215
  _priority_queue->remove(sample);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   216
  _list->release(sample);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   217
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   218
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   219
void ObjectSampler::oops_do(BoolObjectClosure* is_alive, OopClosure* f) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   220
  assert(is_created(), "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   221
  assert(SafepointSynchronize::is_at_safepoint(), "invariant");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   222
  ObjectSampler& sampler = instance();
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   223
  ObjectSample* current = sampler._list->last();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   224
  while (current != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   225
    ObjectSample* next = current->next();
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   226
    if (!current->is_dead()) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   227
      if (is_alive->do_object_b(current->object())) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   228
        // The weakly referenced object is alive, update pointer
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   229
        f->do_oop(const_cast<oop*>(current->object_addr()));
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   230
      } else {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   231
        current->set_dead();
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   232
        sampler._dead_samples = true;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   233
      }
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   234
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   235
    current = next;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   236
  }
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   237
  sampler._last_sweep = JfrTicks::now();
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   238
}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   239
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   240
ObjectSample* ObjectSampler::last() const {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   241
  return _list->last();
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   242
}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   243
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   244
const ObjectSample* ObjectSampler::first() const {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   245
  return _list->first();
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   246
}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   247
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   248
const ObjectSample* ObjectSampler::last_resolved() const {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   249
  return _list->last_resolved();
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   250
}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   251
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   252
void ObjectSampler::set_last_resolved(const ObjectSample* sample) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   253
  _list->set_last_resolved(sample);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   254
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   255
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   256
int ObjectSampler::item_count() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   257
  return _priority_queue->count();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   258
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   259
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   260
const ObjectSample* ObjectSampler::item_at(int index) const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   261
  return _priority_queue->item_at(index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   262
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   263
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   264
ObjectSample* ObjectSampler::item_at(int index) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   265
  return const_cast<ObjectSample*>(
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   266
    const_cast<const ObjectSampler*>(this)->item_at(index)
57870
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 52850
diff changeset
   267
                                  );
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   268
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   269
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   270
const JfrTicks& ObjectSampler::last_sweep() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   271
  return _last_sweep;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   272
}