src/hotspot/share/jfr/leakprofiler/sampling/objectSampler.cpp
author mgronlun
Wed, 28 Aug 2019 12:03:58 +0200
branchJEP-349-branch
changeset 57902 f6502e486572
parent 57870 00860d9caf4d
child 57934 9c150f2b1fea
permissions -rw-r--r--
simplifications
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");
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
   113
  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
   114
    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
   115
  }
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
  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
   117
  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
   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
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   120
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
   121
  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
   122
  if (JfrEventSetting::has_stacktrace(EventOldObjectSample::eventId)) {
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   123
    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
   124
  }
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
}
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
   126
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
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
   128
  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
   129
  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
   130
  const traceid thread_id = get_thread_id(thread);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   131
  if (thread_id == 0) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   132
    return;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   133
  }
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   134
  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
   135
  // 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
   136
  JfrTryLock tryLock(&_lock);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   137
  if (!tryLock.has_lock()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   138
    log_trace(jfr, oldobject, sampling)("Skipping old object sample due to lock contention");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   139
    return;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   140
  }
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   141
  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
   142
}
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
   143
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   144
void ObjectSampler::add(HeapWord* obj, size_t allocated, traceid thread_id, JavaThread* thread) {
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   145
  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
   146
  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
   147
  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
   148
  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
   149
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   150
  if (_dead_samples) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   151
    scavenge();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   152
    assert(!_dead_samples, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   153
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   154
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   155
  _total_allocated += allocated;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   156
  const size_t span = _total_allocated - _priority_queue->total();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   157
  ObjectSample* sample;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   158
  if ((size_t)_priority_queue->count() == _size) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   159
    assert(_list->count() == _size, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   160
    const ObjectSample* peek = _priority_queue->peek();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   161
    if (peek->span() > span) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   162
      // quick reject, will not fit
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   163
      return;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   164
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   165
    sample = _list->reuse(_priority_queue->pop());
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   166
  } else {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   167
    sample = _list->get();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   168
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   169
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   170
  assert(sample != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   171
  sample->set_thread_id(thread_id);
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   172
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   173
  const JfrThreadLocal* const tl = thread->jfr_thread_local();
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   174
  sample->set_thread_checkpoint(tl->thread_checkpoint());
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   175
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   176
  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
   177
  if (stacktrace_hash != 0) {
57902
f6502e486572 simplifications
mgronlun
parents: 57870
diff changeset
   178
    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
   179
    sample->set_stack_trace_hash(stacktrace_hash);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   180
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   181
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   182
  sample->set_span(allocated);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   183
  sample->set_object((oop)obj);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   184
  sample->set_allocated(allocated);
50880
e1117321adaf 8197425: Liveset information for Old Object sample event
egahlin
parents: 50113
diff changeset
   185
  sample->set_allocation_time(JfrTicks::now());
e1117321adaf 8197425: Liveset information for Old Object sample event
egahlin
parents: 50113
diff changeset
   186
  sample->set_heap_used_at_last_gc(Universe::get_heap_used_at_last_gc());
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   187
  _priority_queue->push(sample);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   188
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   189
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
   190
void ObjectSampler::scavenge() {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   191
  ObjectSample* current = _list->last();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   192
  while (current != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   193
    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
   194
    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
   195
      remove_dead(current);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   196
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   197
    current = next;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   198
  }
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
   199
  _dead_samples = false;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   200
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   201
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   202
void ObjectSampler::remove_dead(ObjectSample* sample) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   203
  assert(sample != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   204
  assert(sample->is_dead(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   205
  ObjectSample* const previous = sample->prev();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   206
  // push span on to previous
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   207
  if (previous != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   208
    _priority_queue->remove(previous);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   209
    previous->add_span(sample->span());
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   210
    _priority_queue->push(previous);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   211
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   212
  _priority_queue->remove(sample);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   213
  _list->release(sample);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   214
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   215
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
   216
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
   217
  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
   218
  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
   219
  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
   220
  ObjectSample* current = sampler._list->last();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   221
  while (current != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   222
    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
   223
    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
   224
      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
   225
        // 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
   226
        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
   227
      } 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
   228
        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
   229
        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
   230
      }
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   231
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   232
    current = next;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   233
  }
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
   234
  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
   235
}
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
   236
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
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
   238
  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
   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
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
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
   242
  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
   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
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
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
   246
  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
   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
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
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
   250
  _list->set_last_resolved(sample);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   251
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   252
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   253
int ObjectSampler::item_count() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   254
  return _priority_queue->count();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   255
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   256
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   257
const ObjectSample* ObjectSampler::item_at(int index) const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   258
  return _priority_queue->item_at(index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   259
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   260
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   261
ObjectSample* ObjectSampler::item_at(int index) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   262
  return const_cast<ObjectSample*>(
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   263
    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
   264
                                  );
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   265
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   266
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   267
const JfrTicks& ObjectSampler::last_sweep() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   268
  return _last_sweep;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   269
}