Path: blob/master/src/hotspot/share/jfr/metadata/jfrSerializer.hpp
41152 views
/*1* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_JFR_METADATA_JFRSERIALIZER_HPP25#define SHARE_JFR_METADATA_JFRSERIALIZER_HPP2627#include "memory/allocation.hpp"28#include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp"29#include "jfrfiles/jfrTypes.hpp"3031/*32* A "type" in Jfr is a binary relation defined by enumerating a set of <key, value> ordered pairs:33*34* { <1, myvalue>, <2, mysecondvalue>, ... }35*36* The key should be a type relative unique id. A value is an instance of the type.37*38* By defining and registering a type, keys can be written to event fields and the39* framework will maintain the mapping to the corresponding value (if you register as below).40*41* Inherit JfrSerializer, create a CHeapObj instance and then use JfrSerializer::register_serializer(...) to register.42* Once registered, the ownership of the serializer instance is transferred to Jfr.43*44* How to register:45*46* bool register_serializer(JfrTypeId id, bool require_safepoint, bool permit_cache, JfrSerializer* serializer)47*48* The type identifiers are machine generated into an enum located in jfrfiles/jfrTypes.hpp (included).49*50* enum JfrTypeId {51* ...52* TYPE_THREADGROUP,53* TYPE_CLASSLOADER,54* TYPE_METHOD,55* TYPE_SYMBOL,56* TYPE_THREADSTATE,57* TYPE_INFLATECAUSE,58* ...59*60* id this is the id of the type your are defining (see the enum above).61* require_safepoint indicate if your type need to be evaluated and serialized under a safepoint.62* permit_cache indicate if your type constants are stable to be cached.63* (implies the callback is invoked only once and the contents will be cached. Set this to true for static information).64* serializer the serializer instance.65*66* See below for guidance about how to implement serialize().67*68*/69class JfrSerializer : public CHeapObj<mtTracing> {70public:71virtual ~JfrSerializer() {}72virtual void on_rotation() {}73static bool register_serializer(JfrTypeId id, bool permit_cache, JfrSerializer* serializer);74virtual void serialize(JfrCheckpointWriter& writer) = 0;75};7677/*78* Defining serialize(JfrCheckpointWriter& writer):79*80* Invoke writer.write_count(N) for the number of ordered pairs (cardinality) to be defined.81*82* You then write each individual ordered pair, <key, value> ...83*84* Here is a simple example, describing a type defining string constants:85*86* void MyType::serialize(JfrCheckpointWriter& writer) {87* const int nof_causes = ObjectSynchronizer::inflate_cause_nof;88* writer.write_count(nof_causes); // write number of ordered pairs (mappings) to follow89* for (int i = 0; i < nof_causes; i++) {90* writer.write_key(i); // write key91* writer.write(ObjectSynchronizer::inflate_cause_name((ObjectSynchronizer::InflateCause)i)); // write value92* }93* }94*95* Note that values can be complex, and can also referer to other types.96*97* Please see jfr/recorder/checkpoint/types/jfrType.cpp for reference.98*/99100#endif // SHARE_JFR_METADATA_JFRSERIALIZER_HPP101102103