author | redestad |
Wed, 30 Oct 2019 16:14:56 +0100 | |
changeset 58861 | 2c3cc4b01880 |
parent 58132 | caa25ab47aca |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
53762 | 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/dcmd/jfrDcmds.hpp" |
|
27 |
#include "jfr/recorder/jfrRecorder.hpp" |
|
28 |
#include "jfr/recorder/repository/jfrChunkState.hpp" |
|
29 |
#include "jfr/recorder/repository/jfrChunkWriter.hpp" |
|
30 |
#include "jfr/utilities/jfrTime.hpp" |
|
31 |
#include "jfr/utilities/jfrTimeConverter.hpp" |
|
32 |
#include "logging/log.hpp" |
|
33 |
#include "runtime/os.inline.hpp" |
|
34 |
#include "runtime/thread.inline.hpp" |
|
35 |
||
36 |
JfrChunkState::JfrChunkState() : |
|
37 |
_path(NULL), |
|
38 |
_start_ticks(0), |
|
39 |
_start_nanos(0), |
|
40 |
_previous_start_ticks(0), |
|
41 |
_previous_start_nanos(0), |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
42 |
_last_checkpoint_offset(0) {} |
50113 | 43 |
|
44 |
JfrChunkState::~JfrChunkState() { |
|
45 |
reset(); |
|
46 |
} |
|
47 |
||
48 |
void JfrChunkState::reset() { |
|
49 |
if (_path != NULL) { |
|
50 |
JfrCHeapObj::free(_path, strlen(_path) + 1); |
|
51 |
_path = NULL; |
|
52 |
} |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
53 |
set_last_checkpoint_offset(0); |
50113 | 54 |
} |
55 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
56 |
void JfrChunkState::set_last_checkpoint_offset(int64_t offset) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
57 |
_last_checkpoint_offset = offset; |
50113 | 58 |
} |
59 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
60 |
int64_t JfrChunkState::last_checkpoint_offset() const { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
61 |
return _last_checkpoint_offset; |
50113 | 62 |
} |
63 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53762
diff
changeset
|
64 |
int64_t JfrChunkState::previous_start_ticks() const { |
50113 | 65 |
return _previous_start_ticks; |
66 |
} |
|
67 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53762
diff
changeset
|
68 |
int64_t JfrChunkState::previous_start_nanos() const { |
50113 | 69 |
return _previous_start_nanos; |
70 |
} |
|
71 |
||
72 |
void JfrChunkState::update_start_ticks() { |
|
73 |
_start_ticks = JfrTicks::now(); |
|
74 |
} |
|
75 |
||
76 |
void JfrChunkState::update_start_nanos() { |
|
77 |
_start_nanos = os::javaTimeMillis() * JfrTimeConverter::NANOS_PER_MILLISEC; |
|
78 |
} |
|
79 |
||
80 |
void JfrChunkState::save_current_and_update_start_ticks() { |
|
81 |
_previous_start_ticks = _start_ticks; |
|
82 |
update_start_ticks(); |
|
83 |
} |
|
84 |
||
85 |
void JfrChunkState::save_current_and_update_start_nanos() { |
|
86 |
_previous_start_nanos = _start_nanos; |
|
87 |
update_start_nanos(); |
|
88 |
} |
|
89 |
||
90 |
void JfrChunkState::update_time_to_now() { |
|
91 |
save_current_and_update_start_nanos(); |
|
92 |
save_current_and_update_start_ticks(); |
|
93 |
} |
|
94 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53762
diff
changeset
|
95 |
int64_t JfrChunkState::last_chunk_duration() const { |
50113 | 96 |
return _start_nanos - _previous_start_nanos; |
97 |
} |
|
98 |
||
99 |
static char* copy_path(const char* path) { |
|
100 |
assert(path != NULL, "invariant"); |
|
101 |
const size_t path_len = strlen(path); |
|
102 |
char* new_path = JfrCHeapObj::new_array<char>(path_len + 1); |
|
53762 | 103 |
strncpy(new_path, path, path_len + 1); |
50113 | 104 |
return new_path; |
105 |
} |
|
106 |
||
107 |
void JfrChunkState::set_path(const char* path) { |
|
108 |
assert(JfrStream_lock->owned_by_self(), "invariant"); |
|
109 |
if (_path != NULL) { |
|
110 |
JfrCHeapObj::free(_path, strlen(_path) + 1); |
|
111 |
_path = NULL; |
|
112 |
} |
|
113 |
if (path != NULL) { |
|
114 |
_path = copy_path(path); |
|
115 |
} |
|
116 |
} |
|
117 |
||
118 |
const char* JfrChunkState::path() const { |
|
119 |
return _path; |
|
120 |
} |