src/hotspot/share/jfr/writers/jfrTypeWriterHost.hpp
author alanb
Sat, 30 Nov 2019 16:21:19 +0000
changeset 59329 289000934908
parent 58132 caa25ab47aca
child 58157 9dca61a7df19
permissions -rw-r--r--
8234805: (dc) Remove JNI upcall from DatagramChannel.receive implementation Reviewed-by: dfuchs, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58132
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
     1
/*
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
     4
 *
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
     8
 *
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    13
 * accompanied this code).
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    14
 *
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    18
 *
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    21
 * questions.
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    22
 *
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    23
 */
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    24
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    25
#ifndef SHARE_JFR_WRITERS_JFRTYPEWRITERHOST_HPP
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    26
#define SHARE_JFR_WRITERS_JFRTYPEWRITERHOST_HPP
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    27
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    28
#include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp"
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    29
#include "jfr/utilities/jfrTypes.hpp"
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    30
#include "memory/allocation.hpp"
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    31
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    32
template <typename WriterImpl, u4 ID>
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    33
class JfrTypeWriterHost : public StackObj {
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    34
 private:
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    35
  WriterImpl _impl;
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    36
  JfrCheckpointWriter* _writer;
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    37
  JfrCheckpointContext _ctx;
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    38
  int64_t _count_offset;
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    39
  int _count;
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    40
  bool _skip_header;
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    41
 public:
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    42
  JfrTypeWriterHost(JfrCheckpointWriter* writer,
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    43
                    bool class_unload = false,
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    44
                    bool skip_header = false) : _impl(writer, class_unload),
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    45
                                                _writer(writer),
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    46
                                                _ctx(writer->context()),
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    47
                                                _count(0),
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    48
                                                _skip_header(skip_header) {
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    49
    assert(_writer != NULL, "invariant");
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    50
    if (!_skip_header) {
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    51
      _writer->write_type((JfrTypeId)ID);
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    52
      _count_offset = _writer->reserve(sizeof(u4)); // Don't know how many yet
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    53
    }
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    54
  }
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    55
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    56
  ~JfrTypeWriterHost() {
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    57
    if (_count == 0) {
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    58
      // nothing written, restore context for rewind
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    59
      _writer->set_context(_ctx);
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    60
      return;
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    61
    }
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    62
    assert(_count > 0, "invariant");
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    63
    if (!_skip_header) {
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    64
      _writer->write_count(_count, _count_offset);
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    65
    }
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    66
  }
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    67
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    68
  bool operator()(typename WriterImpl::Type const & value) {
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    69
    this->_count += _impl(value);
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    70
    return true;
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    71
  }
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    72
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    73
  int count() const   { return _count; }
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    74
  void add(int count) { _count += count; }
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    75
};
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    76
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    77
typedef int(*type_write_operation)(JfrCheckpointWriter*, const void*);
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    78
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    79
template <typename T, type_write_operation op>
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    80
class JfrTypeWriterImplHost {
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    81
 private:
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    82
  JfrCheckpointWriter* _writer;
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    83
 public:
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    84
  typedef T Type;
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    85
  JfrTypeWriterImplHost(JfrCheckpointWriter* writer, bool class_unload = false) : _writer(writer) {}
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    86
  int operator()(T const& value) {
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    87
    return op(this->_writer, value);
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    88
  }
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    89
};
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    90
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    91
template <typename T, typename Predicate, type_write_operation op>
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    92
class JfrPredicatedTypeWriterImplHost : public JfrTypeWriterImplHost<T, op> {
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    93
 private:
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    94
  Predicate _predicate;
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    95
  typedef JfrTypeWriterImplHost<T, op> Parent;
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    96
 public:
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    97
  JfrPredicatedTypeWriterImplHost(JfrCheckpointWriter* writer, bool class_unload = false) :
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    98
    Parent(writer), _predicate(class_unload) {}
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
    99
  int operator()(T const& value) {
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
   100
    return _predicate(value) ? Parent::operator()(value) : 0;
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
   101
  }
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
   102
};
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
   103
caa25ab47aca 8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
diff changeset
   104
#endif // SHARE_JFR_WRITERS_JFRTYPEWRITERHOST_HPP