1 /*
   2  * Copyright (c) 2017, 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 #ifndef SHARE_VM_LEAKPROFILER_CHECKPOINT_OBJECTSAMPLEDESCRIPTION_HPP
  26 #define SHARE_VM_LEAKPROFILER_CHECKPOINT_OBJECTSAMPLEDESCRIPTION_HPP
  27 
  28 #define OBJECT_SAMPLE_DESCRIPTION_BUFFER_SIZE 100
  29 
  30 #include "memory/allocation.hpp"
  31 
  32 class outputStream;
  33 
  34 class ObjectDescriptionBuilder : public StackObj {
  35 private:
  36   char _buffer[OBJECT_SAMPLE_DESCRIPTION_BUFFER_SIZE];
  37   size_t _index;
  38 
  39 public:
  40   ObjectDescriptionBuilder();
  41 
  42   void write_text(const char* text);
  43   void write_int(jint value);
  44   void reset();
  45 
  46   void print_description(outputStream* out);
  47   const char* description();
  48 };
  49 
  50 class ObjectSampleDescription : public StackObj {
  51 private:
  52   ObjectDescriptionBuilder _description;
  53   oop _object;
  54 
  55   void write_text(const char* text);
  56   void write_int(jint value);
  57 
  58   void write_object_details();
  59   void write_size(jint size);
  60   void write_thread_name();
  61   void write_thread_group_name();
  62   void write_class_name();
  63   void write_object_to_buffer();
  64   bool is_class(Symbol* s1, const char* s2);
  65   void ensure_initialized();
  66   bool read_int_size(jint* result);
  67 
  68 public:
  69   ObjectSampleDescription(oop object);
  70   void print_description(outputStream* out);
  71   const char* description();
  72 };
  73 
  74 #endif // SHARE_VM_LEAKPROFILER_CHECKPOINT_OBJECTSAMPLEDESCRIPTION_HPP