src/hotspot/share/jfr/recorder/repository/jfrChunkWriter.cpp
author mgronlun
Sun, 15 Sep 2019 15:31:04 +0200
branchJEP-349-branch
changeset 58158 369ebc2a11c2
parent 58157 9dca61a7df19
permissions -rw-r--r--
updates after merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     1
/*
54263
3cabb47758c9 8217362: Emergency dump does not work when disk=false is set
mgronlun
parents: 53897
diff changeset
     2
 * Copyright (c) 2012, 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"
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    26
#include "jfr/recorder/repository/jfrChunk.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    27
#include "jfr/recorder/repository/jfrChunkWriter.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    28
#include "jfr/utilities/jfrTime.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    29
#include "runtime/mutexLocker.hpp"
50117
fb66b2959eaf 8203251: Non-PCH build failed after JDK-8199712 (Flight Recorder)
shade
parents: 50113
diff changeset
    30
#include "runtime/os.inline.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    31
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    32
static const int64_t MAGIC_OFFSET = 0;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    33
static const int64_t MAGIC_LEN = 4;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    34
static const int64_t VERSION_OFFSET = MAGIC_LEN;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    35
static const int64_t SIZE_OFFSET = 8;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    36
static const int64_t SLOT_SIZE = 8;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    37
static const int64_t CHECKPOINT_OFFSET = SIZE_OFFSET + SLOT_SIZE;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    38
static const int64_t METADATA_OFFSET = CHECKPOINT_OFFSET + SLOT_SIZE;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    39
static const int64_t START_NANOS_OFFSET = METADATA_OFFSET + SLOT_SIZE;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    40
static const int64_t DURATION_NANOS_OFFSET = START_NANOS_OFFSET + SLOT_SIZE;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    41
static const int64_t START_TICKS_OFFSET = DURATION_NANOS_OFFSET + SLOT_SIZE;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    42
static const int64_t CPU_FREQUENCY_OFFSET = START_TICKS_OFFSET + SLOT_SIZE;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    43
static const int64_t GENERATION_OFFSET = CPU_FREQUENCY_OFFSET + SLOT_SIZE;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    44
static const int64_t CAPABILITY_OFFSET = GENERATION_OFFSET + 2;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    45
static const int64_t HEADER_SIZE = CAPABILITY_OFFSET + 2;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    46
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    47
static fio_fd open_chunk(const char* path) {
54263
3cabb47758c9 8217362: Emergency dump does not work when disk=false is set
mgronlun
parents: 53897
diff changeset
    48
  return path != NULL ? os::open(path, O_CREAT | O_RDWR, S_IREAD | S_IWRITE) : invalid_fd;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    49
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    50
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
    51
#ifdef ASSERT
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
    52
static void assert_writer_position(JfrChunkWriter* writer, int64_t offset) {
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
    53
  assert(writer != 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
    54
  assert(offset == writer->current_offset(), "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
    55
}
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
    56
#endif
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
    57
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    58
class JfrChunkHeadWriter : public StackObj {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    59
 private:
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    60
  JfrChunkWriter* _writer;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    61
  JfrChunk* _chunk;
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
    62
 public:
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    63
  void write_magic() {
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
    64
    _writer->bytes(_chunk->magic(), MAGIC_LEN);
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    65
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    66
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    67
  void write_version() {
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
    _writer->be_write(_chunk->major_version());
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
    _writer->be_write(_chunk->minor_version());
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    70
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    71
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    72
  void write_size(int64_t size) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    73
    _writer->be_write(size);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    74
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    75
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    76
  void write_checkpoint() {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    77
    _writer->be_write(_chunk->last_checkpoint_offset());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    78
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    79
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    80
  void write_metadata() {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    81
    _writer->be_write(_chunk->last_metadata_offset());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    82
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    83
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    84
  void write_time(bool finalize) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    85
    if (finalize) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    86
      _writer->be_write(_chunk->previous_start_nanos());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    87
      _writer->be_write(_chunk->last_chunk_duration());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    88
      _writer->be_write(_chunk->previous_start_ticks());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    89
      return;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    90
    }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    91
    _writer->be_write(_chunk->start_nanos());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    92
    _writer->be_write(_chunk->duration());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    93
    _writer->be_write(_chunk->start_ticks());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    94
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    95
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    96
  void write_cpu_frequency() {
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
    97
    _writer->be_write(_chunk->cpu_frequency());
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    98
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    99
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   100
  void write_generation(bool finalize) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   101
    _writer->be_write(finalize ? COMPLETE : _chunk->generation());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   102
    _writer->be_write(PAD);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   103
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   104
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
   105
  void write_next_generation() {
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
   106
    _writer->be_write(_chunk->next_generation());
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
   107
    _writer->be_write(PAD);
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
   108
  }
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
   109
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   110
  void write_guard() {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   111
    _writer->be_write(GUARD);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   112
    _writer->be_write(PAD);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   113
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   114
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   115
  void write_guard_flush() {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   116
    write_guard();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   117
    _writer->flush();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   118
  }
57360
5d043a159d5c Preview
egahlin
parents: 54263
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 write_capabilities() {
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->be_write(_chunk->capabilities());
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   122
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   123
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
   124
  void write_size_to_generation(int64_t size, bool finalize) {
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   125
    write_size(size);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   126
    write_checkpoint();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   127
    write_metadata();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   128
    write_time(finalize);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   129
    write_cpu_frequency();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   130
    write_generation(finalize);
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
  }
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
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
  void flush(int64_t size, bool finalize) {
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
    assert(_writer->is_valid(), "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
   135
    assert(_chunk != 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
   136
    DEBUG_ONLY(assert_writer_position(_writer, SIZE_OFFSET);)
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
   137
    write_size_to_generation(size, finalize);
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   138
    // no need to write capabilities
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   139
    _writer->seek(size); // implicit flush
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   140
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   141
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
   142
  void initialize() {
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
   143
    assert(_writer->is_valid(), "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
   144
    assert(_chunk != 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
   145
    DEBUG_ONLY(assert_writer_position(_writer, 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
    write_magic();
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
    write_version();
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
    write_size_to_generation(HEADER_SIZE, false);
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
    write_capabilities();
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
    DEBUG_ONLY(assert_writer_position(_writer, HEADER_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
   151
    _writer->flush();
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
  }
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
58073
76d4428af8b6 flush chunk
mgronlun
parents: 58068
diff changeset
   154
  JfrChunkHeadWriter(JfrChunkWriter* writer, int64_t offset, bool guard = true) : _writer(writer), _chunk(writer->_chunk) {
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   155
    assert(_writer != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   156
    assert(_writer->is_valid(), "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   157
    assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   158
    if (0 == _writer->current_offset()) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   159
      assert(HEADER_SIZE == offset, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   160
      initialize();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   161
    } else {
58073
76d4428af8b6 flush chunk
mgronlun
parents: 58068
diff changeset
   162
      if (guard) {
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
   163
        _writer->seek(GENERATION_OFFSET);
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
        write_guard();
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
        _writer->seek(offset);
58082
0c9dd7f5d23a update nanos for flush chunk
mgronlun
parents: 58073
diff changeset
   166
      } else {
0c9dd7f5d23a update nanos for flush chunk
mgronlun
parents: 58073
diff changeset
   167
        _chunk->update_current_nanos();
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
   168
      }
57360
5d043a159d5c Preview
egahlin
parents: 54263
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
    DEBUG_ONLY(assert_writer_position(_writer, offset);)
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   171
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   172
};
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   173
58073
76d4428af8b6 flush chunk
mgronlun
parents: 58068
diff changeset
   174
static int64_t prepare_chunk_header_constant_pool(JfrChunkWriter& cw, int64_t event_offset, bool flushpoint) {
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
   175
  const int64_t delta = cw.last_checkpoint_offset() == 0 ? 0 : cw.last_checkpoint_offset() - event_offset;
57983
a57907813a83 old object sample blob:ification and serialization support
mgronlun
parents: 57887
diff changeset
   176
  const u4 checkpoint_type = flushpoint ? (u4)(FLUSH | HEADER) : (u4)HEADER;
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
   177
  cw.reserve(sizeof(u4));
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
  cw.write<u8>(EVENT_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: 57360
diff changeset
   179
  cw.write<u8>(JfrTicks::now().value());
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
  cw.write<u8>(0); // duration
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
  cw.write<u8>(delta); // to previous checkpoint
57983
a57907813a83 old object sample blob:ification and serialization support
mgronlun
parents: 57887
diff changeset
   182
  cw.write<u4>(checkpoint_type);
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
   183
  cw.write<u4>(1); // pool count
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
   184
  cw.write<u8>(TYPE_CHUNKHEADER);
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
   185
  cw.write<u4>(1); // count
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
  cw.write<u8>(1); // key
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
  cw.write<u4>(HEADER_SIZE); // length of byte array
58073
76d4428af8b6 flush chunk
mgronlun
parents: 58068
diff changeset
   188
  return cw.current_offset();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   189
}
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
int64_t JfrChunkWriter::write_chunk_header_checkpoint(bool flushpoint) {
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
  assert(this->has_valid_fd(), "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
   193
  const int64_t event_size_offset = current_offset();
58073
76d4428af8b6 flush chunk
mgronlun
parents: 58068
diff changeset
   194
  const int64_t header_content_pos = prepare_chunk_header_constant_pool(*this, event_size_offset, flushpoint);
76d4428af8b6 flush chunk
mgronlun
parents: 58068
diff changeset
   195
  JfrChunkHeadWriter head(this, header_content_pos, false);
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
   196
  head.write_magic();
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
   197
  head.write_version();
58073
76d4428af8b6 flush chunk
mgronlun
parents: 58068
diff changeset
   198
  const int64_t chunk_size_offset = reserve(sizeof(int64_t)); // size to be decided when we are done
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
   199
  be_write(event_size_offset); // last checkpoint offset will be this 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: 57360
diff changeset
   200
  head.write_metadata();
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
  head.write_time(false);
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
  head.write_cpu_frequency();
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
  head.write_next_generation();
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
  head.write_capabilities();
58073
76d4428af8b6 flush chunk
mgronlun
parents: 58068
diff changeset
   205
  assert(current_offset() - header_content_pos == HEADER_SIZE, "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
   206
  const u4 checkpoint_size = current_offset() - event_size_offset;
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
  write_padded_at_offset<u4>(checkpoint_size, event_size_offset);
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
  set_last_checkpoint_offset(event_size_offset);
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 size_t sz_written = size_written();
58073
76d4428af8b6 flush chunk
mgronlun
parents: 58068
diff changeset
   210
  write_be_at_offset(sz_written, chunk_size_offset);
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
  return sz_written;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   212
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   213
58073
76d4428af8b6 flush chunk
mgronlun
parents: 58068
diff changeset
   214
int64_t JfrChunkWriter::flush_chunk(bool flushpoint) {
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
   215
  assert(_chunk != 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
   216
  const int64_t sz_written = write_chunk_header_checkpoint(flushpoint);
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
   217
  assert(size_written() == sz_written, "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
   218
  JfrChunkHeadWriter head(this, SIZE_OFFSET);
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
   219
  head.flush(sz_written, !flushpoint);
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
   220
  return sz_written;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   221
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   222
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   223
JfrChunkWriter::JfrChunkWriter() : JfrChunkWriterBase(NULL), _chunk(new JfrChunk()) {}
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   224
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   225
JfrChunkWriter::~JfrChunkWriter() {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   226
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   227
  delete _chunk;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   228
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   229
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   230
void JfrChunkWriter::set_path(const char* path) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   231
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   232
  _chunk->set_path(path);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   233
}
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   234
57887
a9cc3698a55c some cleanup
mgronlun
parents: 57886
diff changeset
   235
void JfrChunkWriter::set_time_stamp() {
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   236
  assert(_chunk != NULL, "invariant");
57887
a9cc3698a55c some cleanup
mgronlun
parents: 57886
diff changeset
   237
  _chunk->set_time_stamp();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   238
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   239
53897
0abec72a3ac2 8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents: 50117
diff changeset
   240
int64_t JfrChunkWriter::size_written() const {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   241
  return this->is_valid() ? this->current_offset() : 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   242
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   243
58132
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents: 54263
diff changeset
   244
int64_t JfrChunkWriter::last_checkpoint_offset() const {
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   245
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   246
  return _chunk->last_checkpoint_offset();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   247
}
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   248
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   249
int64_t JfrChunkWriter::current_chunk_start_nanos() const {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   250
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   251
  return this->is_valid() ? _chunk->start_nanos() : invalid_time;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   252
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   253
58132
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents: 54263
diff changeset
   254
void JfrChunkWriter::set_last_checkpoint_offset(int64_t offset) {
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   255
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   256
  _chunk->set_last_checkpoint_offset(offset);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   257
}
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   258
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   259
void JfrChunkWriter::set_last_metadata_offset(int64_t offset) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   260
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   261
  _chunk->set_last_metadata_offset(offset);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   262
}
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   263
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   264
bool JfrChunkWriter::has_metadata() const {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   265
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   266
  return _chunk->has_metadata();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   267
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   268
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   269
bool JfrChunkWriter::open() {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   270
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   271
  JfrChunkWriterBase::reset(open_chunk(_chunk->path()));
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   272
  const bool is_open = this->has_valid_fd();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   273
  if (is_open) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   274
    assert(0 == this->current_offset(), "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   275
    _chunk->reset();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   276
    JfrChunkHeadWriter head(this, HEADER_SIZE);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   277
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   278
  return is_open;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   279
}
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   280
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   281
int64_t JfrChunkWriter::close() {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   282
  assert(this->has_valid_fd(), "invariant");
58073
76d4428af8b6 flush chunk
mgronlun
parents: 58068
diff changeset
   283
  const int64_t size_written = flush_chunk(false);
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   284
  this->close_fd();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   285
  assert(!this->is_valid(), "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   286
  return size_written;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   287
}