1 | /* |
2 | * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. |
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/repository/jfrChunkRotation.hpp" |
28 | #include "jfr/recorder/repository/jfrChunkWriter.hpp" |
29 | #include "runtime/handles.inline.hpp" |
30 | |
31 | static jobject chunk_monitor = NULL; |
32 | static int64_t threshold = 0; |
33 | static bool rotate = false; |
34 | |
35 | static jobject install_chunk_monitor(Thread* thread) { |
36 | assert(chunk_monitor == NULL, "invariant" ); |
37 | // read static field |
38 | HandleMark hm(thread); |
39 | static const char klass[] = "jdk/jfr/internal/JVM" ; |
40 | static const char field[] = "FILE_DELTA_CHANGE" ; |
41 | static const char signature[] = "Ljava/lang/Object;" ; |
42 | JavaValue result(T_OBJECT); |
43 | JfrJavaArguments field_args(&result, klass, field, signature, thread); |
44 | JfrJavaSupport::get_field_global_ref(&field_args, thread); |
45 | chunk_monitor = result.get_jobject(); |
46 | return chunk_monitor; |
47 | } |
48 | |
49 | // lazy install |
50 | static jobject get_chunk_monitor(Thread* thread) { |
51 | return chunk_monitor != NULL ? chunk_monitor : install_chunk_monitor(thread); |
52 | } |
53 | |
54 | static void notify() { |
55 | Thread* const thread = Thread::current(); |
56 | JfrJavaSupport::notify_all(get_chunk_monitor(thread), thread); |
57 | } |
58 | |
59 | void JfrChunkRotation::evaluate(const JfrChunkWriter& writer) { |
60 | assert(threshold > 0, "invariant" ); |
61 | if (rotate) { |
62 | // already in progress |
63 | return; |
64 | } |
65 | if (writer.size_written() > threshold) { |
66 | rotate = true; |
67 | notify(); |
68 | } |
69 | } |
70 | |
71 | bool JfrChunkRotation::should_rotate() { |
72 | return rotate; |
73 | } |
74 | |
75 | void JfrChunkRotation::on_rotation() { |
76 | rotate = false; |
77 | } |
78 | |
79 | void JfrChunkRotation::set_threshold(int64_t bytes) { |
80 | threshold = bytes; |
81 | } |
82 | |