50113
|
1 |
/*
|
57360
|
2 |
* Copyright (c) 2016, 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/jni/jfrJavaSupport.hpp"
|
|
27 |
#include "jfr/recorder/checkpoint/jfrMetadataEvent.hpp"
|
|
28 |
#include "jfr/recorder/repository/jfrChunkWriter.hpp"
|
|
29 |
#include "oops/klass.inline.hpp"
|
|
30 |
#include "oops/oop.inline.hpp"
|
|
31 |
#include "oops/typeArrayOop.inline.hpp"
|
|
32 |
#include "runtime/thread.inline.hpp"
|
|
33 |
|
|
34 |
static jbyteArray _metadata_blob = NULL;
|
57360
|
35 |
static u8 metadata_id = 0;
|
|
36 |
static u8 last_written_metadata_id = 0;
|
50113
|
37 |
|
|
38 |
static void write_metadata_blob(JfrChunkWriter& chunkwriter, jbyteArray metadata_blob) {
|
|
39 |
if (metadata_blob != NULL) {
|
|
40 |
const typeArrayOop arr = (typeArrayOop)JfrJavaSupport::resolve_non_null(metadata_blob);
|
|
41 |
assert(arr != NULL, "invariant");
|
|
42 |
const int length = arr->length();
|
|
43 |
const Klass* const k = arr->klass();
|
|
44 |
assert(k != NULL && k->is_array_klass(), "invariant");
|
|
45 |
const TypeArrayKlass* const byte_arr_klass = TypeArrayKlass::cast(k);
|
|
46 |
const jbyte* const data_address = arr->byte_at_addr(0);
|
|
47 |
chunkwriter.write_unbuffered(data_address, length);
|
|
48 |
}
|
|
49 |
}
|
|
50 |
|
57360
|
51 |
void JfrMetadataEvent::write(JfrChunkWriter& chunkwriter) {
|
50113
|
52 |
assert(chunkwriter.is_valid(), "invariant");
|
57360
|
53 |
const jlong metadata_offset = chunkwriter.current_offset();
|
50113
|
54 |
assert(chunkwriter.current_offset() == metadata_offset, "invariant");
|
57360
|
55 |
|
|
56 |
if (last_written_metadata_id == metadata_id && chunkwriter.has_metadata()) {
|
|
57 |
return;
|
|
58 |
}
|
|
59 |
|
50113
|
60 |
// header
|
|
61 |
chunkwriter.reserve(sizeof(u4));
|
|
62 |
chunkwriter.write<u8>(EVENT_METADATA); // ID 0
|
|
63 |
// time data
|
|
64 |
chunkwriter.write(JfrTicks::now());
|
|
65 |
chunkwriter.write((u8)0); // duration
|
57360
|
66 |
chunkwriter.write(metadata_id); // metadata id
|
50113
|
67 |
write_metadata_blob(chunkwriter, _metadata_blob); // payload
|
57360
|
68 |
last_written_metadata_id = metadata_id;
|
50113
|
69 |
// fill in size of metadata descriptor event
|
|
70 |
const jlong size_written = chunkwriter.current_offset() - metadata_offset;
|
|
71 |
chunkwriter.write_padded_at_offset((u4)size_written, metadata_offset);
|
57360
|
72 |
chunkwriter.set_last_metadata_offset(metadata_offset);
|
50113
|
73 |
}
|
|
74 |
|
|
75 |
void JfrMetadataEvent::update(jbyteArray metadata) {
|
|
76 |
JavaThread* thread = (JavaThread*)Thread::current();
|
|
77 |
assert(thread->is_Java_thread(), "invariant");
|
|
78 |
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(thread));
|
|
79 |
if (_metadata_blob != NULL) {
|
|
80 |
JfrJavaSupport::destroy_global_jni_handle(_metadata_blob);
|
|
81 |
}
|
|
82 |
const oop new_desc_oop = JfrJavaSupport::resolve_non_null(metadata);
|
|
83 |
_metadata_blob = new_desc_oop != NULL ? (jbyteArray)JfrJavaSupport::global_jni_handle(new_desc_oop, thread) : NULL;
|
57360
|
84 |
++metadata_id;
|
50113
|
85 |
}
|