src/hotspot/share/jfr/recorder/stacktrace/jfrStackTraceRepository.cpp
author mgronlun
Sun, 25 Aug 2019 13:27:54 +0200
branchJEP-349-branch
changeset 57872 7aa1b3d6ff8f
parent 57870 00860d9caf4d
child 57902 f6502e486572
permissions -rw-r--r--
stacktrace serialization cache
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"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    30
#include "runtime/mutexLocker.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    31
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    32
static JfrStackTraceRepository* _instance = NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    33
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
    34
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
    35
  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
    36
}
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
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    38
JfrStackTraceRepository& JfrStackTraceRepository::instance() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    39
  return *_instance;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    40
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    41
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    42
JfrStackTraceRepository* JfrStackTraceRepository::create() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    43
  assert(_instance == NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    44
  _instance = new JfrStackTraceRepository();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    45
  return _instance;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    46
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    47
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    48
class JfrFrameType : public JfrSerializer {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    49
 public:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    50
  void serialize(JfrCheckpointWriter& writer) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    51
    writer.write_count(JfrStackFrame::NUM_FRAME_TYPES);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    52
    writer.write_key(JfrStackFrame::FRAME_INTERPRETER);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    53
    writer.write("Interpreted");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    54
    writer.write_key(JfrStackFrame::FRAME_JIT);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    55
    writer.write("JIT compiled");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    56
    writer.write_key(JfrStackFrame::FRAME_INLINE);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    57
    writer.write("Inlined");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    58
    writer.write_key(JfrStackFrame::FRAME_NATIVE);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    59
    writer.write("Native");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    60
  }
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
bool JfrStackTraceRepository::initialize() {
57360
5d043a159d5c Preview
egahlin
parents: 54623
diff changeset
    64
  return JfrSerializer::register_serializer(TYPE_FRAMETYPE, true, new JfrFrameType());
50113
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: 57360
diff changeset
    67
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
    68
  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
    69
  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
    70
  _instance = NULL;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    71
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    72
57872
7aa1b3d6ff8f stacktrace serialization cache
mgronlun
parents: 57870
diff changeset
    73
static traceid last_id = 0;
7aa1b3d6ff8f stacktrace serialization cache
mgronlun
parents: 57870
diff changeset
    74
7aa1b3d6ff8f stacktrace serialization cache
mgronlun
parents: 57870
diff changeset
    75
bool JfrStackTraceRepository::is_modified() const {
7aa1b3d6ff8f stacktrace serialization cache
mgronlun
parents: 57870
diff changeset
    76
  return last_id != _next_id;
7aa1b3d6ff8f stacktrace serialization cache
mgronlun
parents: 57870
diff changeset
    77
}
7aa1b3d6ff8f stacktrace serialization cache
mgronlun
parents: 57870
diff changeset
    78
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    79
size_t JfrStackTraceRepository::write_impl(JfrChunkWriter& sw, bool clear) {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54603
diff changeset
    80
  MutexLocker lock(JfrStacktrace_lock, Mutex::_no_safepoint_check_flag);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    81
  assert(_entries > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    82
  int count = 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    83
  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
    84
    JfrStackTrace* stacktrace = _table[i];
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    85
    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
    86
      JfrStackTrace* next = const_cast<JfrStackTrace*>(stacktrace->next());
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    87
      if (stacktrace->should_write()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    88
        stacktrace->write(sw);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    89
        ++count;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    90
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    91
      if (clear) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    92
        delete stacktrace;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    93
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    94
      stacktrace = next;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    95
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    96
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    97
  if (clear) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    98
    memset(_table, 0, sizeof(_table));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    99
    _entries = 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   100
  }
57872
7aa1b3d6ff8f stacktrace serialization cache
mgronlun
parents: 57870
diff changeset
   101
  last_id = _next_id;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   102
  return count;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   103
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   104
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   105
size_t JfrStackTraceRepository::write(JfrChunkWriter& sw, bool clear) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   106
  return _entries > 0 ? write_impl(sw, clear) : 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   107
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   108
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   109
traceid JfrStackTraceRepository::write(JfrCheckpointWriter& writer, traceid id, unsigned int hash) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   110
  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
   111
  const JfrStackTrace* const trace = lookup(hash, id);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   112
  assert(trace != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   113
  assert(trace->hash() == hash, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   114
  assert(trace->id() == id, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   115
  trace->write(writer);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   116
  return id;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   117
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   118
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
   119
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
   120
  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
   121
  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
   122
  fct.serialize(writer);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   123
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   124
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
   125
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
   126
  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
   127
  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
   128
    return 0;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   129
  }
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
   130
  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
   131
    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
   132
    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
   133
      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
   134
      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
   135
      stacktrace = next;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   136
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   137
  }
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
   138
  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
   139
  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
   140
  _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
   141
  return processed;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   142
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   143
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
   144
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
   145
  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
   146
  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
   147
  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
   148
  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
   149
    return tl->cached_stack_trace_id();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   150
  }
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
   151
  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
   152
    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
   153
  }
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
  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
   155
  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
   156
    // 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
   157
    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
   158
  }
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
  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
   160
  assert(tl->stackframes() == frames, "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
  return instance().record_for((JavaThread*)thread, skip,frames, tl->stackdepth());
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   162
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   163
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
   164
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
   165
  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
   166
  return stacktrace.record_safe(thread, skip) ? add(stacktrace) : 0;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   167
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   168
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
   169
traceid JfrStackTraceRepository::add(const JfrStackTrace* stacktrace, 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: 57360
diff changeset
   170
  assert(stacktrace != 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
   171
  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: 57360
diff changeset
   172
  assert(stacktrace->hash() != 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
   173
  return add(*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
   174
}
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   175
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
   176
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
   177
  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
   178
  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
   179
    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
   180
    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
   181
  }
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
   182
  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
   183
  return tid;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   184
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   185
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
   186
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
   187
  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
   188
  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
   189
  const JfrStackTrace* table_entry = _table[index];
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   190
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
   191
  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
   192
    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
   193
      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
   194
    }
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
    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
   196
  }
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
  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
   199
    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
   200
  }
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
  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
   203
  _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
   204
  ++_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
   205
  return id;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   206
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   207
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   208
// 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
   209
const JfrStackTrace* JfrStackTraceRepository::lookup(unsigned int hash, traceid id) const {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   210
  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
   211
  const JfrStackTrace* trace = _table[index];
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   212
  while (trace != NULL && trace->id() != id) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   213
    trace = trace->next();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   214
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   215
  assert(trace != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   216
  assert(trace->hash() == hash, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   217
  assert(trace->id() == id, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   218
  return trace;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   219
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   220
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
   221
bool JfrStackTraceRepository::fill_stacktrace_for(JavaThread* thread, JfrStackTrace* stacktrace, int skip) {
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
   222
  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
   223
  assert(stacktrace != 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
   224
  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
   225
  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
   226
  const unsigned int cached_stacktrace_hash = tl->cached_stack_trace_hash();
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
   227
  if (cached_stacktrace_hash != 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
   228
    stacktrace->set_hash(cached_stacktrace_hash);
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
   229
    return true;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   230
  }
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
   231
  return stacktrace->record_safe(thread, skip);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   232
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   233