src/hotspot/share/jfr/recorder/repository/jfrChunkWriter.cpp
author mgronlun
Mon, 02 Sep 2019 19:42:46 +0200
branchJEP-349-branch
changeset 57983 a57907813a83
parent 57887 a9cc3698a55c
child 58068 22dab580786c
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
/*
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 "jfr/utilities/jfrTypes.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    30
#include "runtime/mutexLocker.hpp"
50117
fb66b2959eaf 8203251: Non-PCH build failed after JDK-8199712 (Flight Recorder)
shade
parents: 50113
diff changeset
    31
#include "runtime/os.inline.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    32
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    33
static const int64_t MAGIC_OFFSET = 0;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    34
static const int64_t MAGIC_LEN = 4;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    35
static const int64_t VERSION_OFFSET = MAGIC_LEN;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    36
static const int64_t SIZE_OFFSET = 8;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    37
static const int64_t SLOT_SIZE = 8;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    38
static const int64_t CHECKPOINT_OFFSET = SIZE_OFFSET + SLOT_SIZE;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    39
static const int64_t METADATA_OFFSET = CHECKPOINT_OFFSET + SLOT_SIZE;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    40
static const int64_t START_NANOS_OFFSET = METADATA_OFFSET + SLOT_SIZE;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    41
static const int64_t DURATION_NANOS_OFFSET = START_NANOS_OFFSET + SLOT_SIZE;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    42
static const int64_t START_TICKS_OFFSET = DURATION_NANOS_OFFSET + SLOT_SIZE;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    43
static const int64_t CPU_FREQUENCY_OFFSET = START_TICKS_OFFSET + SLOT_SIZE;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    44
static const int64_t GENERATION_OFFSET = CPU_FREQUENCY_OFFSET + SLOT_SIZE;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    45
static const int64_t CAPABILITY_OFFSET = GENERATION_OFFSET + 2;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    46
static const int64_t HEADER_SIZE = CAPABILITY_OFFSET + 2;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    47
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    48
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
    49
  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
    50
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    51
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
    52
#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
    53
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
    54
  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
    55
  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
    56
}
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
#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
    58
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    59
class JfrChunkHeadWriter : public StackObj {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    60
 private:
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    61
  JfrChunkWriter* _writer;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    62
  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
    63
 public:
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    64
  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
    65
    _writer->bytes(_chunk->magic(), MAGIC_LEN);
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    66
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    67
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    68
  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
    69
    _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
    70
    _writer->be_write(_chunk->minor_version());
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    71
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    72
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    73
  void write_size(int64_t size) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    74
    _writer->be_write(size);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    75
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    76
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    77
  void write_checkpoint() {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    78
    _writer->be_write(_chunk->last_checkpoint_offset());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    79
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    80
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    81
  void write_metadata() {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    82
    _writer->be_write(_chunk->last_metadata_offset());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    83
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    84
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    85
  void write_time(bool finalize) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    86
    if (finalize) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    87
      _writer->be_write(_chunk->previous_start_nanos());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    88
      _writer->be_write(_chunk->last_chunk_duration());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    89
      _writer->be_write(_chunk->previous_start_ticks());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    90
      return;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    91
    }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    92
    _writer->be_write(_chunk->start_nanos());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    93
    _writer->be_write(_chunk->duration());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    94
    _writer->be_write(_chunk->start_ticks());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    95
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    96
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    97
  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
    98
    _writer->be_write(_chunk->cpu_frequency());
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
    99
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   100
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   101
  void write_generation(bool finalize) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   102
    _writer->be_write(finalize ? COMPLETE : _chunk->generation());
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   103
    _writer->be_write(PAD);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   104
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   105
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
   106
  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
   107
    _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
   108
    _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
   109
  }
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
   110
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   111
  void write_guard() {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   112
    _writer->be_write(GUARD);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   113
    _writer->be_write(PAD);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   114
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   115
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   116
  void write_guard_flush() {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   117
    write_guard();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   118
    _writer->flush();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   119
  }
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   120
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
   121
  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
   122
    _writer->be_write(_chunk->capabilities());
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   123
  }
5d043a159d5c Preview
egahlin
parents: 54263
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
  void write_size_to_generation(int64_t size, bool finalize) {
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   126
    write_size(size);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   127
    write_checkpoint();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   128
    write_metadata();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   129
    write_time(finalize);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   130
    write_cpu_frequency();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   131
    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
   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
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
  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
   135
    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
   136
    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
   137
    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
   138
    write_size_to_generation(size, finalize);
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   139
    // no need to write capabilities
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   140
    _writer->seek(size); // implicit flush
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   141
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   142
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
   143
  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
   144
    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
   145
    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
   146
    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
   147
    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
   148
    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
   149
    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
   150
    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
   151
    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
   152
    _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
   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
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
  JfrChunkHeadWriter(JfrChunkWriter* writer, int64_t offset, bool head = true) : _writer(writer), _chunk(writer->_chunk) {
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   156
    assert(_writer != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   157
    assert(_writer->is_valid(), "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   158
    assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   159
    if (0 == _writer->current_offset()) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   160
      assert(HEADER_SIZE == offset, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   161
      initialize();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   162
    } else {
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
      if (head) {
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
        _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
   165
        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
   166
        _writer->seek(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
   167
      }
57360
5d043a159d5c Preview
egahlin
parents: 54263
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
    DEBUG_ONLY(assert_writer_position(_writer, offset);)
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   170
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   171
};
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   172
57886
87f8a814310d rename from JfrCheckpointMode to JfrCheckpointType
mgronlun
parents: 57882
diff changeset
   173
static void write_checkpoint_header(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
   174
  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
   175
  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
   176
  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
   177
  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
   178
  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
   179
  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
   180
  cw.write<u8>(delta); // to previous checkpoint
57983
a57907813a83 old object sample blob:ification and serialization support
mgronlun
parents: 57887
diff changeset
   181
  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
   182
  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
   183
  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
   184
  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
   185
  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
   186
  cw.write<u4>(HEADER_SIZE); // length of byte array
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
}
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
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
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
   190
  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
   191
  const int64_t event_size_offset = current_offset();
57886
87f8a814310d rename from JfrCheckpointMode to JfrCheckpointType
mgronlun
parents: 57882
diff changeset
   192
  write_checkpoint_header(*this, event_size_offset, 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
   193
  const int64_t start_offset = current_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
   194
  JfrChunkHeadWriter head(this, start_offset, 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
   195
  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
   196
  head.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
   197
  const int64_t size_offset = reserve(sizeof(int64_t));
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
  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
   199
  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
   200
  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
   201
  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
   202
  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
   203
  head.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
   204
  assert(current_offset() - start_offset == HEADER_SIZE, "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
   205
  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
   206
  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
   207
  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
   208
  const size_t sz_written = size_written();
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
  write_be_at_offset(sz_written, 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
   210
  return sz_written;
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
}
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
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
   213
int64_t JfrChunkWriter::flushpoint(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
   214
  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
   215
  if (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
   216
    _chunk->update();
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
  }
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 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
   219
  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
   220
  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
   221
  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
   222
  return sz_written;
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
}
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
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   225
JfrChunkWriter::JfrChunkWriter() : JfrChunkWriterBase(NULL), _chunk(new JfrChunk()) {}
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   226
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   227
JfrChunkWriter::~JfrChunkWriter() {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   228
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   229
  delete _chunk;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   230
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   231
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   232
void JfrChunkWriter::set_path(const char* path) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   233
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   234
  _chunk->set_path(path);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   235
}
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   236
57887
a9cc3698a55c some cleanup
mgronlun
parents: 57886
diff changeset
   237
void JfrChunkWriter::set_time_stamp() {
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   238
  assert(_chunk != NULL, "invariant");
57887
a9cc3698a55c some cleanup
mgronlun
parents: 57886
diff changeset
   239
  _chunk->set_time_stamp();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   240
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   241
53897
0abec72a3ac2 8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents: 50117
diff changeset
   242
int64_t JfrChunkWriter::size_written() const {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   243
  return this->is_valid() ? this->current_offset() : 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   244
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   245
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   246
int64_t JfrChunkWriter::last_checkpoint_offset() const {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   247
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   248
  return _chunk->last_checkpoint_offset();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   249
}
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   250
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   251
int64_t JfrChunkWriter::current_chunk_start_nanos() const {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   252
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   253
  return this->is_valid() ? _chunk->start_nanos() : invalid_time;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   254
}
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   255
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   256
void JfrChunkWriter::set_last_checkpoint_offset(int64_t offset) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   257
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   258
  _chunk->set_last_checkpoint_offset(offset);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   259
}
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   260
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   261
bool JfrChunkWriter::is_initial_flushpoint_for_chunk() const {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   262
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   263
  assert(_chunk->is_started(), "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   264
  assert(!_chunk->is_finished(), "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   265
  return _chunk->is_initial_flush();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   266
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   267
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   268
void JfrChunkWriter::set_last_metadata_offset(int64_t offset) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   269
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   270
  _chunk->set_last_metadata_offset(offset);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   271
}
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   272
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   273
bool JfrChunkWriter::has_metadata() const {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   274
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   275
  return _chunk->has_metadata();
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   276
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   277
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   278
bool JfrChunkWriter::open() {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   279
  assert(_chunk != NULL, "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   280
  JfrChunkWriterBase::reset(open_chunk(_chunk->path()));
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   281
  const bool is_open = this->has_valid_fd();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   282
  if (is_open) {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   283
    assert(0 == this->current_offset(), "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   284
    _chunk->reset();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   285
    JfrChunkHeadWriter head(this, HEADER_SIZE);
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   286
  }
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   287
  return is_open;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   288
}
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   289
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   290
int64_t JfrChunkWriter::close() {
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   291
  assert(this->has_valid_fd(), "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
   292
  const int64_t size_written = flushpoint(false);
57360
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   293
  this->close_fd();
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   294
  assert(!this->is_valid(), "invariant");
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   295
  return size_written;
5d043a159d5c Preview
egahlin
parents: 54263
diff changeset
   296
}