src/hotspot/share/jfr/recorder/stacktrace/jfrStackTraceRepository.cpp
author mgronlun
Mon, 02 Sep 2019 19:42:46 +0200
branchJEP-349-branch
changeset 57983 a57907813a83
parent 57934 9c150f2b1fea
child 58154 060d9d139109
permissions -rw-r--r--
old object sample blob:ification and serialization support
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     1
/*
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 51263
diff changeset
     2
 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     4
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     8
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    13
 * accompanied this code).
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    14
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    18
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    21
 * questions.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    22
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    23
 */
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    24
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    25
#include "precompiled.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    26
#include "jfr/metadata/jfrSerializer.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: 57360
diff changeset
    27
#include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    28
#include "jfr/recorder/repository/jfrChunkWriter.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    29
#include "jfr/recorder/stacktrace/jfrStackTraceRepository.hpp"
57902
f6502e486572 simplifications
mgronlun
parents: 57872
diff changeset
    30
#include "jfr/support/jfrThreadLocal.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    31
#include "runtime/mutexLocker.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    32
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    33
static JfrStackTraceRepository* _instance = NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    34
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: 57360
diff changeset
    35
JfrStackTraceRepository::JfrStackTraceRepository() : _next_id(0), _entries(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: 57360
diff changeset
    36
  memset(_table, 0, sizeof(_table));
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
    37
}
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
    38
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    39
JfrStackTraceRepository& JfrStackTraceRepository::instance() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    40
  return *_instance;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    41
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    42
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    43
JfrStackTraceRepository* JfrStackTraceRepository::create() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    44
  assert(_instance == NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    45
  _instance = new JfrStackTraceRepository();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    46
  return _instance;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    47
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    48
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    49
class JfrFrameType : public JfrSerializer {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    50
 public:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    51
  void serialize(JfrCheckpointWriter& writer) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    52
    writer.write_count(JfrStackFrame::NUM_FRAME_TYPES);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    53
    writer.write_key(JfrStackFrame::FRAME_INTERPRETER);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    54
    writer.write("Interpreted");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    55
    writer.write_key(JfrStackFrame::FRAME_JIT);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    56
    writer.write("JIT compiled");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    57
    writer.write_key(JfrStackFrame::FRAME_INLINE);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    58
    writer.write("Inlined");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    59
    writer.write_key(JfrStackFrame::FRAME_NATIVE);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    60
    writer.write("Native");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    61
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    62
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    63
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    64
bool JfrStackTraceRepository::initialize() {
57360
5d043a159d5c Preview
egahlin
parents: 54623
diff changeset
    65
  return JfrSerializer::register_serializer(TYPE_FRAMETYPE, true, new JfrFrameType());
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    66
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    67
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: 57360
diff changeset
    68
void JfrStackTraceRepository::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: 57360
diff changeset
    69
  assert(_instance != NULL, "invarinat");
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
    70
  delete _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: 57360
diff changeset
    71
  _instance = NULL;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    72
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    73
57872
7aa1b3d6ff8f stacktrace serialization cache
mgronlun
parents: 57870
diff changeset
    74
static traceid last_id = 0;
7aa1b3d6ff8f stacktrace serialization cache
mgronlun
parents: 57870
diff changeset
    75
7aa1b3d6ff8f stacktrace serialization cache
mgronlun
parents: 57870
diff changeset
    76
bool JfrStackTraceRepository::is_modified() const {
7aa1b3d6ff8f stacktrace serialization cache
mgronlun
parents: 57870
diff changeset
    77
  return last_id != _next_id;
7aa1b3d6ff8f stacktrace serialization cache
mgronlun
parents: 57870
diff changeset
    78
}
7aa1b3d6ff8f stacktrace serialization cache
mgronlun
parents: 57870
diff changeset
    79
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    80
size_t JfrStackTraceRepository::write_impl(JfrChunkWriter& sw, bool clear) {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54603
diff changeset
    81
  MutexLocker lock(JfrStacktrace_lock, Mutex::_no_safepoint_check_flag);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    82
  assert(_entries > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    83
  int count = 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    84
  for (u4 i = 0; i < TABLE_SIZE; ++i) {
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: 57360
diff changeset
    85
    JfrStackTrace* stacktrace = _table[i];
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    86
    while (stacktrace != NULL) {
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: 57360
diff changeset
    87
      JfrStackTrace* next = const_cast<JfrStackTrace*>(stacktrace->next());
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    88
      if (stacktrace->should_write()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    89
        stacktrace->write(sw);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    90
        ++count;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    91
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    92
      if (clear) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    93
        delete stacktrace;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    94
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    95
      stacktrace = next;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    96
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    97
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    98
  if (clear) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    99
    memset(_table, 0, sizeof(_table));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   100
    _entries = 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   101
  }
57872
7aa1b3d6ff8f stacktrace serialization cache
mgronlun
parents: 57870
diff changeset
   102
  last_id = _next_id;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   103
  return count;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   104
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   105
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   106
size_t JfrStackTraceRepository::write(JfrChunkWriter& sw, bool clear) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   107
  return _entries > 0 ? write_impl(sw, clear) : 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   108
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   109
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   110
traceid JfrStackTraceRepository::write(JfrCheckpointWriter& writer, traceid id, unsigned int hash) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   111
  assert(JfrStacktrace_lock->owned_by_self(), "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: 57360
diff changeset
   112
  const JfrStackTrace* const trace = lookup(hash, id);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   113
  assert(trace != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   114
  assert(trace->hash() == hash, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   115
  assert(trace->id() == id, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   116
  trace->write(writer);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   117
  return id;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   118
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   119
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: 57360
diff changeset
   120
void JfrStackTraceRepository::write_metadata(JfrCheckpointWriter& writer) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   121
  JfrFrameType fct;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   122
  writer.write_type(TYPE_FRAMETYPE);
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   123
  fct.serialize(writer);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   124
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   125
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: 57360
diff changeset
   126
size_t JfrStackTraceRepository::clear() {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   127
  MutexLocker lock(JfrStacktrace_lock, Mutex::_no_safepoint_check_flag);
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   128
  if (_entries == 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: 57360
diff changeset
   129
    return 0;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   130
  }
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: 57360
diff changeset
   131
  for (u4 i = 0; i < TABLE_SIZE; ++i) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   132
    JfrStackTrace* stacktrace = _table[i];
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   133
    while (stacktrace != 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: 57360
diff changeset
   134
      JfrStackTrace* next = const_cast<JfrStackTrace*>(stacktrace->next());
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   135
      delete stacktrace;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   136
      stacktrace = next;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   137
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   138
  }
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: 57360
diff changeset
   139
  memset(_table, 0, sizeof(_table));
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   140
  const size_t processed = _entries;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   141
  _entries = 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: 57360
diff changeset
   142
  return processed;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   143
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   144
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: 57360
diff changeset
   145
traceid JfrStackTraceRepository::record(Thread* thread, int skip /* 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: 57360
diff changeset
   146
  assert(thread == Thread::current(), "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: 57360
diff changeset
   147
  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: 57360
diff changeset
   148
  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: 57360
diff changeset
   149
  if (tl->has_cached_stack_trace()) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   150
    return tl->cached_stack_trace_id();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   151
  }
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: 57360
diff changeset
   152
  if (!thread->is_Java_thread() || thread->is_hidden_from_external_view() || tl->is_excluded()) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   153
    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: 57360
diff changeset
   154
  }
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   155
  JfrStackFrame* frames = tl->stackframes();
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   156
  if (frames == 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: 57360
diff changeset
   157
    // pending oom
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   158
    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: 57360
diff changeset
   159
  }
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   160
  assert(frames != 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: 57360
diff changeset
   161
  assert(tl->stackframes() == frames, "invariant");
57902
f6502e486572 simplifications
mgronlun
parents: 57872
diff changeset
   162
  return instance().record_for((JavaThread*)thread, skip, frames, tl->stackdepth());
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   163
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   164
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: 57360
diff changeset
   165
traceid JfrStackTraceRepository::record_for(JavaThread* thread, int skip, JfrStackFrame *frames, u4 max_frames) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   166
  JfrStackTrace stacktrace(frames, max_frames);
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   167
  return stacktrace.record_safe(thread, skip) ? add(stacktrace) : 0;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   168
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   169
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: 57360
diff changeset
   170
traceid JfrStackTraceRepository::add(const JfrStackTrace& stacktrace) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   171
  traceid tid = instance().add_trace(stacktrace);
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   172
  if (tid == 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: 57360
diff changeset
   173
    stacktrace.resolve_linenos();
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   174
    tid = instance().add_trace(stacktrace);
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   175
  }
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   176
  assert(tid != 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: 57360
diff changeset
   177
  return tid;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   178
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   179
57934
9c150f2b1fea optimizations for old object sample metadata
mgronlun
parents: 57902
diff changeset
   180
void JfrStackTraceRepository::record_and_cache(JavaThread* thread, int skip /* 0 */) {
9c150f2b1fea optimizations for old object sample metadata
mgronlun
parents: 57902
diff changeset
   181
  assert(thread != NULL, "invariant");
57902
f6502e486572 simplifications
mgronlun
parents: 57872
diff changeset
   182
  JfrThreadLocal* const tl = thread->jfr_thread_local();
f6502e486572 simplifications
mgronlun
parents: 57872
diff changeset
   183
  assert(tl != NULL, "invariant");
57934
9c150f2b1fea optimizations for old object sample metadata
mgronlun
parents: 57902
diff changeset
   184
  assert(!tl->has_cached_stack_trace(), "invariant");
57902
f6502e486572 simplifications
mgronlun
parents: 57872
diff changeset
   185
  JfrStackTrace stacktrace(tl->stackframes(), tl->stackdepth());
f6502e486572 simplifications
mgronlun
parents: 57872
diff changeset
   186
  stacktrace.record_safe(thread, skip);
57983
a57907813a83 old object sample blob:ification and serialization support
mgronlun
parents: 57934
diff changeset
   187
  const unsigned int hash = stacktrace.hash();
a57907813a83 old object sample blob:ification and serialization support
mgronlun
parents: 57934
diff changeset
   188
  if (hash != 0) {
a57907813a83 old object sample blob:ification and serialization support
mgronlun
parents: 57934
diff changeset
   189
    tl->set_cached_stack_trace_id(instance().add(stacktrace), hash);
a57907813a83 old object sample blob:ification and serialization support
mgronlun
parents: 57934
diff changeset
   190
  }
57902
f6502e486572 simplifications
mgronlun
parents: 57872
diff changeset
   191
}
f6502e486572 simplifications
mgronlun
parents: 57872
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: 57360
diff changeset
   193
traceid JfrStackTraceRepository::add_trace(const JfrStackTrace& stacktrace) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   194
  MutexLocker lock(JfrStacktrace_lock, Mutex::_no_safepoint_check_flag);
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   195
  const size_t index = stacktrace._hash % TABLE_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: 57360
diff changeset
   196
  const JfrStackTrace* table_entry = _table[index];
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   197
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: 57360
diff changeset
   198
  while (table_entry != 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: 57360
diff changeset
   199
    if (table_entry->equals(stacktrace)) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   200
      return table_entry->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: 57360
diff changeset
   201
    }
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   202
    table_entry = table_entry->next();
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   203
  }
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   204
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: 57360
diff changeset
   205
  if (!stacktrace.have_lineno()) {
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   206
    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: 57360
diff changeset
   207
  }
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   208
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   209
  traceid id = ++_next_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: 57360
diff changeset
   210
  _table[index] = new JfrStackTrace(id, stacktrace, _table[index]);
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   211
  ++_entries;
00860d9caf4d New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents: 57360
diff changeset
   212
  return id;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   213
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   214
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   215
// invariant is that the entry to be resolved actually exists in the table
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: 57360
diff changeset
   216
const JfrStackTrace* JfrStackTraceRepository::lookup(unsigned int hash, traceid id) const {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   217
  const size_t index = (hash % TABLE_SIZE);
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: 57360
diff changeset
   218
  const JfrStackTrace* trace = _table[index];
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   219
  while (trace != NULL && trace->id() != id) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   220
    trace = trace->next();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   221
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   222
  assert(trace != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   223
  assert(trace->hash() == hash, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   224
  assert(trace->id() == id, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   225
  return trace;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   226
}