author | mgronlun |
Sat, 24 Aug 2019 14:30:27 +0200 | |
branch | JEP-349-branch |
changeset 57870 | 00860d9caf4d |
parent 57360 | 5d043a159d5c |
child 58068 | 22dab580786c |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
53762 | 2 |
* Copyright (c) 2011, 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/jfr.hpp" |
|
27 |
#include "jfr/jni/jfrJavaSupport.hpp" |
|
28 |
#include "jfr/recorder/jfrRecorder.hpp" |
|
29 |
#include "jfr/recorder/repository/jfrChunkWriter.hpp" |
|
54263
3cabb47758c9
8217362: Emergency dump does not work when disk=false is set
mgronlun
parents:
53897
diff
changeset
|
30 |
#include "jfr/recorder/repository/jfrEmergencyDump.hpp" |
50113 | 31 |
#include "jfr/recorder/repository/jfrRepository.hpp" |
32 |
#include "jfr/recorder/service/jfrPostBox.hpp" |
|
57360 | 33 |
#include "logging/log.hpp" |
50113 | 34 |
#include "memory/resourceArea.hpp" |
35 |
#include "runtime/mutex.hpp" |
|
57360 | 36 |
#include "runtime/os.hpp" |
50113 | 37 |
#include "runtime/thread.inline.hpp" |
38 |
||
39 |
static JfrRepository* _instance = NULL; |
|
40 |
||
41 |
JfrRepository& JfrRepository::instance() { |
|
42 |
return *_instance; |
|
43 |
} |
|
44 |
||
45 |
static JfrChunkWriter* _chunkwriter = NULL; |
|
46 |
||
47 |
||
48 |
JfrChunkWriter& JfrRepository::chunkwriter() { |
|
49 |
return *_chunkwriter; |
|
50 |
} |
|
51 |
||
52 |
JfrRepository::JfrRepository(JfrPostBox& post_box) : _path(NULL), _post_box(post_box) {} |
|
53 |
||
54 |
bool JfrRepository::initialize() { |
|
57360 | 55 |
assert(_chunkwriter == NULL, "invariant"); |
56 |
_chunkwriter = new JfrChunkWriter(); |
|
57 |
return _chunkwriter != NULL; |
|
50113 | 58 |
} |
59 |
||
60 |
JfrRepository::~JfrRepository() { |
|
61 |
if (_path != NULL) { |
|
62 |
JfrCHeapObj::free(_path, strlen(_path) + 1); |
|
63 |
_path = NULL; |
|
64 |
} |
|
65 |
||
66 |
if (_chunkwriter != NULL) { |
|
67 |
delete _chunkwriter; |
|
68 |
_chunkwriter = NULL; |
|
69 |
} |
|
70 |
} |
|
71 |
||
72 |
JfrRepository* JfrRepository::create(JfrPostBox& post_box) { |
|
73 |
assert(_instance == NULL, "invariant"); |
|
74 |
_instance = new JfrRepository(post_box); |
|
75 |
return _instance; |
|
76 |
} |
|
77 |
||
78 |
void JfrRepository::destroy() { |
|
79 |
assert(_instance != NULL, "invariant"); |
|
80 |
delete _instance; |
|
81 |
_instance = NULL; |
|
82 |
} |
|
83 |
||
84 |
void JfrRepository::on_vm_error() { |
|
57360 | 85 |
|
54263
3cabb47758c9
8217362: Emergency dump does not work when disk=false is set
mgronlun
parents:
53897
diff
changeset
|
86 |
if (_path == NULL) { |
50113 | 87 |
// completed already |
88 |
return; |
|
89 |
} |
|
54263
3cabb47758c9
8217362: Emergency dump does not work when disk=false is set
mgronlun
parents:
53897
diff
changeset
|
90 |
JfrEmergencyDump::on_vm_error(_path); |
50113 | 91 |
} |
92 |
||
93 |
bool JfrRepository::set_path(const char* path) { |
|
94 |
assert(path != NULL, "trying to set the repository path with a NULL string!"); |
|
95 |
if (_path != NULL) { |
|
96 |
// delete existing |
|
97 |
JfrCHeapObj::free(_path, strlen(_path) + 1); |
|
98 |
} |
|
99 |
const size_t path_len = strlen(path); |
|
100 |
_path = JfrCHeapObj::new_array<char>(path_len + 1); |
|
101 |
if (_path == NULL) { |
|
102 |
return false; |
|
103 |
} |
|
53762 | 104 |
strncpy(_path, path, path_len + 1); |
50113 | 105 |
return true; |
106 |
} |
|
107 |
||
57360 | 108 |
void JfrRepository::notify_on_new_chunk_path() { |
109 |
if (Jfr::is_recording()) { |
|
110 |
// rotations are synchronous, block until rotation completes |
|
111 |
instance()._post_box.post(MSG_ROTATE); |
|
112 |
} |
|
50113 | 113 |
} |
114 |
||
57360 | 115 |
void JfrRepository::set_chunk_path(const char* path) { |
116 |
chunkwriter().set_path(path); |
|
117 |
} |
|
118 |
||
119 |
jlong JfrRepository::current_chunk_start_nanos() { |
|
120 |
return chunkwriter().current_chunk_start_nanos(); |
|
50113 | 121 |
} |
122 |
||
123 |
/** |
|
124 |
* Sets the file where data should be written. |
|
125 |
* |
|
126 |
* Recording Previous Current Action |
|
127 |
* ============================================== |
|
128 |
* true null null Ignore, keep recording in-memory |
|
129 |
* true null file1 Start disk recording |
|
130 |
* true file null Copy out metadata to disk and continue in-memory recording |
|
131 |
* true file1 file2 Copy out metadata and start with new File (file2) |
|
132 |
* false * null Ignore, but start recording to memory |
|
133 |
* false * file Ignore, but start recording to disk |
|
134 |
*/ |
|
135 |
void JfrRepository::set_chunk_path(jstring path, JavaThread* jt) { |
|
136 |
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(jt)); |
|
137 |
ResourceMark rm(jt); |
|
138 |
const char* const canonical_chunk_path = JfrJavaSupport::c_str(path, jt); |
|
57360 | 139 |
if (NULL == canonical_chunk_path && !_chunkwriter->is_valid()) { |
140 |
// new output is NULL and current output is NULL |
|
141 |
return; |
|
50113 | 142 |
} |
57360 | 143 |
instance().set_chunk_path(canonical_chunk_path); |
50113 | 144 |
notify_on_new_chunk_path(); |
145 |
} |
|
146 |
||
147 |
void JfrRepository::set_path(jstring location, JavaThread* jt) { |
|
148 |
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(jt)); |
|
149 |
ResourceMark rm(jt); |
|
150 |
const char* const path = JfrJavaSupport::c_str(location, jt); |
|
151 |
if (path != NULL) { |
|
152 |
instance().set_path(path); |
|
153 |
} |
|
154 |
} |
|
155 |
||
156 |
bool JfrRepository::open_chunk(bool vm_error /* false */) { |
|
157 |
if (vm_error) { |
|
158 |
ResourceMark rm; |
|
57360 | 159 |
_chunkwriter->set_path(JfrEmergencyDump::build_dump_path(_path)); |
50113 | 160 |
} |
161 |
return _chunkwriter->open(); |
|
162 |
} |
|
163 |
||
57360 | 164 |
size_t JfrRepository::close_chunk() { |
165 |
return _chunkwriter->close(); |
|
50113 | 166 |
} |
57360 | 167 |
|
168 |
void JfrRepository::flush(bool metadata, JavaThread* jt) { |
|
169 |
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(jt)); |
|
170 |
assert(Jfr::is_recording(), "invariant"); |
|
171 |
if (!_chunkwriter->is_valid()) { |
|
172 |
return; |
|
173 |
} |
|
174 |
instance()._post_box.post((metadata || _chunkwriter->is_initial_flushpoint_for_chunk()) ? MSG_FLUSHPOINT_METADATA : MSG_FLUSHPOINT); |
|
175 |
} |
|
176 |
||
177 |
size_t JfrRepository::flush_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
|
178 |
return _chunkwriter->flushpoint(true); |
57360 | 179 |
} |