1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/jfr/recorder/checkpoint/types/jfrTypeSetWriter.hpp Mon Aug 12 18:30:40 2019 +0300 1.3 @@ -0,0 +1,108 @@ 1.4 +/* 1.5 + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_JFR_CHECKPOINT_TYPES_JFRTYPESETWRITER_HPP 1.29 +#define SHARE_VM_JFR_CHECKPOINT_TYPES_JFRTYPESETWRITER_HPP 1.30 + 1.31 +#include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp" 1.32 +#include "jfr/utilities/jfrTypes.hpp" 1.33 +#include "memory/allocation.hpp" 1.34 + 1.35 +template <typename WriterImpl, u4 ID> 1.36 +class JfrArtifactWriterHost : public StackObj { 1.37 + private: 1.38 + WriterImpl _impl; 1.39 + JfrCheckpointWriter* _writer; 1.40 + JfrCheckpointContext _ctx; 1.41 + jlong _count_offset; 1.42 + int _count; 1.43 + bool _skip_header; 1.44 + public: 1.45 + JfrArtifactWriterHost(JfrCheckpointWriter* writer, 1.46 + JfrArtifactSet* artifacts, 1.47 + bool class_unload, 1.48 + bool skip_header = false) : _impl(writer, artifacts, class_unload), 1.49 + _writer(writer), 1.50 + _ctx(writer->context()), 1.51 + _count(0), 1.52 + _skip_header(skip_header) { 1.53 + assert(_writer != NULL, "invariant"); 1.54 + if (!_skip_header) { 1.55 + _writer->write_type((JfrTypeId)ID); 1.56 + _count_offset = _writer->reserve(sizeof(u4)); // Don't know how many yet 1.57 + } 1.58 + } 1.59 + 1.60 + ~JfrArtifactWriterHost() { 1.61 + if (_count == 0) { 1.62 + // nothing written, restore context for rewind 1.63 + _writer->set_context(_ctx); 1.64 + return; 1.65 + } 1.66 + assert(_count > 0, "invariant"); 1.67 + if (!_skip_header) { 1.68 + _writer->write_count(_count, _count_offset); 1.69 + } 1.70 + } 1.71 + 1.72 + bool operator()(typename WriterImpl::Type const & value) { 1.73 + this->_count += _impl(value); 1.74 + return true; 1.75 + } 1.76 + 1.77 + int count() const { return _count; } 1.78 + void add(int count) { _count += count; } 1.79 +}; 1.80 + 1.81 +typedef int(*artifact_write_operation)(JfrCheckpointWriter*, JfrArtifactSet*, const void*); 1.82 + 1.83 +template <typename T, artifact_write_operation op> 1.84 +class JfrArtifactWriterImplHost { 1.85 + private: 1.86 + JfrCheckpointWriter* _writer; 1.87 + JfrArtifactSet* _artifacts; 1.88 + bool _class_unload; 1.89 + public: 1.90 + typedef T Type; 1.91 + JfrArtifactWriterImplHost(JfrCheckpointWriter* writer, JfrArtifactSet* artifacts, bool class_unload) : 1.92 + _writer(writer), _artifacts(artifacts), _class_unload(class_unload) {} 1.93 + int operator()(T const& value) { 1.94 + return op(this->_writer, this->_artifacts, value); 1.95 + } 1.96 +}; 1.97 + 1.98 +template <typename T, typename Predicate, artifact_write_operation op> 1.99 +class JfrPredicatedArtifactWriterImplHost : public JfrArtifactWriterImplHost<T, op> { 1.100 + private: 1.101 + Predicate _predicate; 1.102 + typedef JfrArtifactWriterImplHost<T, op> Parent; 1.103 + public: 1.104 + JfrPredicatedArtifactWriterImplHost(JfrCheckpointWriter* writer, JfrArtifactSet* artifacts, bool class_unload) : 1.105 + Parent(writer, artifacts, class_unload), _predicate(class_unload) {} 1.106 + int operator()(T const& value) { 1.107 + return _predicate(value) ? Parent::operator()(value) : 0; 1.108 + } 1.109 +}; 1.110 + 1.111 +#endif // SHARE_VM_JFR_CHECKPOINT_TYPES_JFRTYPESETWRITER_HPP