author | mgronlun |
Mon, 25 Mar 2019 15:37:06 +0100 | |
changeset 54263 | 3cabb47758c9 |
parent 53897 | 0abec72a3ac2 |
child 57360 | 5d043a159d5c |
child 58132 | caa25ab47aca |
permissions | -rw-r--r-- |
50113 | 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 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#include "precompiled.hpp" |
|
26 |
#include "jfr/recorder/repository/jfrChunkState.hpp" |
|
27 |
#include "jfr/recorder/repository/jfrChunkWriter.hpp" |
|
28 |
#include "jfr/recorder/service/jfrOptionSet.hpp" |
|
29 |
#include "jfr/utilities/jfrTime.hpp" |
|
30 |
#include "jfr/utilities/jfrTypes.hpp" |
|
31 |
#include "runtime/mutexLocker.hpp" |
|
32 |
#include "runtime/os.hpp" |
|
50117
fb66b2959eaf
8203251: Non-PCH build failed after JDK-8199712 (Flight Recorder)
shade
parents:
50113
diff
changeset
|
33 |
#include "runtime/os.inline.hpp" |
50113 | 34 |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50117
diff
changeset
|
35 |
static const u2 JFR_VERSION_MAJOR = 2; |
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50117
diff
changeset
|
36 |
static const u2 JFR_VERSION_MINOR = 0; |
50113 | 37 |
static const size_t MAGIC_LEN = 4; |
38 |
static const size_t FILEHEADER_SLOT_SIZE = 8; |
|
39 |
static const size_t CHUNK_SIZE_OFFSET = 8; |
|
40 |
||
41 |
JfrChunkWriter::JfrChunkWriter() : JfrChunkWriterBase(NULL), _chunkstate(NULL) {} |
|
42 |
||
43 |
bool JfrChunkWriter::initialize() { |
|
44 |
assert(_chunkstate == NULL, "invariant"); |
|
45 |
_chunkstate = new JfrChunkState(); |
|
46 |
return _chunkstate != NULL; |
|
47 |
} |
|
48 |
||
49 |
static fio_fd open_chunk(const char* path) { |
|
50 |
assert(JfrStream_lock->owned_by_self(), "invariant"); |
|
54263
3cabb47758c9
8217362: Emergency dump does not work when disk=false is set
mgronlun
parents:
53897
diff
changeset
|
51 |
return path != NULL ? os::open(path, O_CREAT | O_RDWR, S_IREAD | S_IWRITE) : invalid_fd; |
50113 | 52 |
} |
53 |
||
54 |
bool JfrChunkWriter::open() { |
|
55 |
assert(_chunkstate != NULL, "invariant"); |
|
56 |
JfrChunkWriterBase::reset(open_chunk(_chunkstate->path())); |
|
57 |
const bool is_open = this->has_valid_fd(); |
|
58 |
if (is_open) { |
|
59 |
this->bytes("FLR", MAGIC_LEN); |
|
60 |
this->be_write((u2)JFR_VERSION_MAJOR); |
|
61 |
this->be_write((u2)JFR_VERSION_MINOR); |
|
62 |
this->reserve(6 * FILEHEADER_SLOT_SIZE); |
|
63 |
// u8 chunk_size |
|
64 |
// u8 initial checkpoint offset |
|
65 |
// u8 metadata section offset |
|
66 |
// u8 chunk start nanos |
|
67 |
// u8 chunk duration nanos |
|
68 |
// u8 chunk start ticks |
|
69 |
this->be_write(JfrTime::frequency()); |
|
70 |
// chunk capabilities, CompressedIntegers etc |
|
71 |
this->be_write((u4)JfrOptionSet::compressed_integers() ? 1 : 0); |
|
72 |
_chunkstate->reset(); |
|
73 |
} |
|
74 |
return is_open; |
|
75 |
} |
|
76 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50117
diff
changeset
|
77 |
size_t JfrChunkWriter::close(int64_t metadata_offset) { |
50113 | 78 |
write_header(metadata_offset); |
79 |
this->flush(); |
|
80 |
this->close_fd(); |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50117
diff
changeset
|
81 |
return (size_t)size_written(); |
50113 | 82 |
} |
83 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50117
diff
changeset
|
84 |
void JfrChunkWriter::write_header(int64_t metadata_offset) { |
50113 | 85 |
assert(this->is_valid(), "invariant"); |
86 |
// Chunk size |
|
87 |
this->write_be_at_offset(size_written(), CHUNK_SIZE_OFFSET); |
|
88 |
// initial checkpoint event offset |
|
89 |
this->write_be_at_offset(_chunkstate->previous_checkpoint_offset(), CHUNK_SIZE_OFFSET + (1 * FILEHEADER_SLOT_SIZE)); |
|
90 |
// metadata event offset |
|
91 |
this->write_be_at_offset(metadata_offset, CHUNK_SIZE_OFFSET + (2 * FILEHEADER_SLOT_SIZE)); |
|
92 |
// start of chunk in nanos since epoch |
|
93 |
this->write_be_at_offset(_chunkstate->previous_start_nanos(), CHUNK_SIZE_OFFSET + (3 * FILEHEADER_SLOT_SIZE)); |
|
94 |
// duration of chunk in nanos |
|
95 |
this->write_be_at_offset(_chunkstate->last_chunk_duration(), CHUNK_SIZE_OFFSET + (4 * FILEHEADER_SLOT_SIZE)); |
|
96 |
// start of chunk in ticks |
|
97 |
this->write_be_at_offset(_chunkstate->previous_start_ticks(), CHUNK_SIZE_OFFSET + (5 * FILEHEADER_SLOT_SIZE)); |
|
98 |
} |
|
99 |
||
100 |
void JfrChunkWriter::set_chunk_path(const char* chunk_path) { |
|
101 |
_chunkstate->set_path(chunk_path); |
|
102 |
} |
|
103 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50117
diff
changeset
|
104 |
int64_t JfrChunkWriter::size_written() const { |
50113 | 105 |
return this->is_valid() ? this->current_offset() : 0; |
106 |
} |
|
107 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50117
diff
changeset
|
108 |
int64_t JfrChunkWriter::previous_checkpoint_offset() const { |
50113 | 109 |
return _chunkstate->previous_checkpoint_offset(); |
110 |
} |
|
111 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50117
diff
changeset
|
112 |
void JfrChunkWriter::set_previous_checkpoint_offset(int64_t offset) { |
50113 | 113 |
_chunkstate->set_previous_checkpoint_offset(offset); |
114 |
} |
|
115 |
||
116 |
void JfrChunkWriter::time_stamp_chunk_now() { |
|
117 |
_chunkstate->update_time_to_now(); |
|
118 |
} |