author | mgronlun |
Fri, 11 Oct 2019 19:46:05 +0200 | |
branch | JEP-349-branch |
changeset 58567 | e77a97d0edbb |
parent 58166 | 105d32b27809 |
permissions | -rw-r--r-- |
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 |
||
58166 | 34 |
static jbyteArray metadata_blob = NULL; |
57360 | 35 |
static u8 metadata_id = 0; |
58567
e77a97d0edbb
Metadata races (TestStart) and thread exclusion inclusion (TestRecursive)
mgronlun
parents:
58166
diff
changeset
|
36 |
static u8 last_metadata_id = 0; |
50113 | 37 |
|
58166 | 38 |
static void write_metadata_blob(JfrChunkWriter& chunkwriter) { |
39 |
assert(metadata_blob != NULL, "invariant"); |
|
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); |
|
50113 | 48 |
} |
49 |
||
57360 | 50 |
void JfrMetadataEvent::write(JfrChunkWriter& chunkwriter) { |
50113 | 51 |
assert(chunkwriter.is_valid(), "invariant"); |
58567
e77a97d0edbb
Metadata races (TestStart) and thread exclusion inclusion (TestRecursive)
mgronlun
parents:
58166
diff
changeset
|
52 |
if (last_metadata_id == metadata_id && chunkwriter.has_metadata()) { |
57360 | 53 |
return; |
54 |
} |
|
50113 | 55 |
// header |
58166 | 56 |
const int64_t metadata_offset = chunkwriter.reserve(sizeof(u4)); |
50113 | 57 |
chunkwriter.write<u8>(EVENT_METADATA); // ID 0 |
58 |
// time data |
|
59 |
chunkwriter.write(JfrTicks::now()); |
|
60 |
chunkwriter.write((u8)0); // duration |
|
57360 | 61 |
chunkwriter.write(metadata_id); // metadata id |
58166 | 62 |
write_metadata_blob(chunkwriter); // payload |
50113 | 63 |
// fill in size of metadata descriptor event |
58166 | 64 |
const int64_t size_written = chunkwriter.current_offset() - metadata_offset; |
50113 | 65 |
chunkwriter.write_padded_at_offset((u4)size_written, metadata_offset); |
57360 | 66 |
chunkwriter.set_last_metadata_offset(metadata_offset); |
58567
e77a97d0edbb
Metadata races (TestStart) and thread exclusion inclusion (TestRecursive)
mgronlun
parents:
58166
diff
changeset
|
67 |
last_metadata_id = metadata_id; |
50113 | 68 |
} |
69 |
||
70 |
void JfrMetadataEvent::update(jbyteArray metadata) { |
|
71 |
JavaThread* thread = (JavaThread*)Thread::current(); |
|
72 |
assert(thread->is_Java_thread(), "invariant"); |
|
73 |
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(thread)); |
|
58166 | 74 |
if (metadata_blob != NULL) { |
75 |
JfrJavaSupport::destroy_global_jni_handle(metadata_blob); |
|
50113 | 76 |
} |
77 |
const oop new_desc_oop = JfrJavaSupport::resolve_non_null(metadata); |
|
58166 | 78 |
assert(new_desc_oop != NULL, "invariant"); |
79 |
metadata_blob = (jbyteArray)JfrJavaSupport::global_jni_handle(new_desc_oop, thread); |
|
57360 | 80 |
++metadata_id; |
50113 | 81 |
} |