src/hotspot/share/jfr/recorder/repository/jfrChunkRotation.cpp
author mgronlun
Wed, 30 Oct 2019 19:43:52 +0100
changeset 58863 c16ac7a2eba4
parent 53897 0abec72a3ac2
permissions -rw-r--r--
8226511: Implement JFR Event Streaming Reviewed-by: egahlin, mseledtsov, mgronlun Contributed-by: erik.gahlin@oracle.com, mikhailo.seledtsov@oracle.com, markus.gronlund@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53014
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
     1
/*
53582
881c5fbeb849 8218041: Assorted wrong/missing includes
rehn
parents: 53014
diff changeset
     2
 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
53014
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
     4
 *
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
     8
 *
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    13
 * accompanied this code).
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    14
 *
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    18
 *
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    21
 * questions.
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    22
 *
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    23
 */
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    24
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    25
#include "precompiled.hpp"
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    26
#include "jfr/jni/jfrJavaSupport.hpp"
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    27
#include "jfr/recorder/repository/jfrChunkRotation.hpp"
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    28
#include "jfr/recorder/repository/jfrChunkWriter.hpp"
53582
881c5fbeb849 8218041: Assorted wrong/missing includes
rehn
parents: 53014
diff changeset
    29
#include "runtime/handles.inline.hpp"
53014
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    30
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    31
static jobject chunk_monitor = NULL;
53897
0abec72a3ac2 8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents: 53582
diff changeset
    32
static int64_t threshold = 0;
53014
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    33
static bool rotate = false;
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    34
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    35
static jobject install_chunk_monitor(Thread* thread) {
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    36
  assert(chunk_monitor == NULL, "invariant");
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    37
  // read static field
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    38
  HandleMark hm(thread);
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    39
  static const char klass[] = "jdk/jfr/internal/JVM";
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    40
  static const char field[] = "FILE_DELTA_CHANGE";
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    41
  static const char signature[] = "Ljava/lang/Object;";
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    42
  JavaValue result(T_OBJECT);
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    43
  JfrJavaArguments field_args(&result, klass, field, signature, thread);
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    44
  JfrJavaSupport::get_field_global_ref(&field_args, thread);
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    45
  chunk_monitor = result.get_jobject();
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    46
  return chunk_monitor;
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    47
}
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    48
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    49
// lazy install
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    50
static jobject get_chunk_monitor(Thread* thread) {
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    51
  return chunk_monitor != NULL ? chunk_monitor : install_chunk_monitor(thread);
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    52
}
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    53
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    54
static void notify() {
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    55
  Thread* const thread = Thread::current();
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    56
  JfrJavaSupport::notify_all(get_chunk_monitor(thread), thread);
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    57
}
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    58
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    59
void JfrChunkRotation::evaluate(const JfrChunkWriter& writer) {
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    60
  assert(threshold > 0, "invariant");
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    61
  if (rotate) {
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    62
    // already in progress
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    63
    return;
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    64
  }
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    65
  if (writer.size_written() > threshold) {
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    66
    rotate = true;
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    67
    notify();
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    68
  }
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    69
}
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    70
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    71
bool JfrChunkRotation::should_rotate() {
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    72
  return rotate;
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    73
}
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    74
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    75
void JfrChunkRotation::on_rotation() {
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    76
  rotate = false;
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    77
}
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    78
53897
0abec72a3ac2 8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents: 53582
diff changeset
    79
void JfrChunkRotation::set_threshold(int64_t bytes) {
53014
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    80
  threshold = bytes;
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents:
diff changeset
    81
}