Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/demo/jvmti/hprof/hprof.h
38829 views
/*1* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6*7* - Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9*10* - Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* - Neither the name of Oracle nor the names of its15* contributors may be used to endorse or promote products derived16* from this software without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS19* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,20* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR21* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR22* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,23* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,24* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR25* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF26* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING27* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS28* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.29*/3031/*32* This source code is provided to illustrate the usage of a given feature33* or technique and has been deliberately simplified. Additional steps34* required for a production-quality application, such as security checks,35* input validation and proper error handling, might not be present in36* this sample code.37*/383940/* Primary hprof #include file, should be included by most if not41* all hprof source files. Gives access to the global data structure42* and all global macros, and everything declared in the #include43* files of each of the source files.44*/4546#ifndef HPROF_H47#define HPROF_H4849/* Standard C functions used throughout. */5051#include <stdio.h>52#include <stdlib.h>53#include <ctype.h>54#include <string.h>55#include <stddef.h>56#include <stdarg.h>57#include <limits.h>58#include <time.h>59#include <errno.h>6061/* General JVM/Java functions, types and macros. */6263#include <sys/types.h>64#include "jni.h"65#include "jvmti.h"66#include "classfile_constants.h"67#include "jvm_md.h"6869#ifndef SKIP_NPT70#include "npt.h" /* To get NptEnv for doing character conversions */71#endif7273/* Macros to extract the upper and lower 32 bits of a jlong */7475#define jlong_high(a) ((jint)((a)>>32))76#define jlong_low(a) ((jint)(a))77#define jlong_to_jint(a) ((jint)(a))78#define jint_to_jlong(a) ((jlong)(a))7980#define jlong_add(a, b) ((a) + (b))818283/* The type used to contain a generic 32bit "serial number". */8485typedef unsigned SerialNumber;8687/* How the options get to OnLoad: */8889#define AGENTNAME "hprof"90#define XRUN "-Xrun" AGENTNAME91#define AGENTLIB "-agentlib:" AGENTNAME9293/* Name of prelude file, found at runtime relative to java binary location */9495#define PRELUDE_FILE "jvm.hprof.txt"9697/* File I/O buffer size to be used with any file i/o operation */9899#define FILE_IO_BUFFER_SIZE (1024*64)100101/* Machine dependent functions. */102103#include "hprof_md.h"104105/* Table index types */106107typedef unsigned TableIndex;108typedef TableIndex ClassIndex;109typedef TableIndex FrameIndex;110typedef TableIndex IoNameIndex;111typedef TableIndex MonitorIndex;112typedef TableIndex ObjectIndex;113typedef TableIndex LoaderIndex;114typedef TableIndex RefIndex;115typedef TableIndex SiteIndex;116typedef TableIndex StringIndex;117typedef TableIndex TlsIndex;118typedef TableIndex TraceIndex;119120/* Index for method tables in classes */121122typedef int MethodIndex;123124/* The different kinds of class status bits. */125126enum ClassStatus {127CLASS_PREPARED = 0x00000001,128CLASS_LOADED = 0x00000002,129CLASS_UNLOADED = 0x00000004,130CLASS_SPECIAL = 0x00000008,131CLASS_IN_LOAD_LIST = 0x00000010,132CLASS_SYSTEM = 0x00000020,133CLASS_DUMPED = 0x00000040134};135typedef jint ClassStatus;136137/* The different kind of objects we track with heap=dump */138139typedef unsigned char ObjectKind;140enum {141OBJECT_NORMAL = 1,142OBJECT_CLASS = 2,143OBJECT_SYSTEM = 3,144OBJECT_HPROF = 4,145OBJECT_LOADER = 5146};147148/* Used by site_write() when writing out the heap=sites data. */149150enum {151SITE_DUMP_INCREMENTAL = 0x01,152SITE_SORT_BY_ALLOC = 0x02,153SITE_FORCE_GC = 0x04154};155156/* Used to hold information about a field, and potentially a value too. */157158typedef struct FieldInfo {159ClassIndex cnum;160StringIndex name_index;161StringIndex sig_index;162unsigned short modifiers;163unsigned char primType;164unsigned char primSize;165} FieldInfo;166167/* Used to hold information about a constant pool entry value for a class. */168169typedef struct ConstantPoolValue {170unsigned constant_pool_index;171StringIndex sig_index;172jvalue value;173} ConstantPoolValue;174175/* All machine independent functions */176177#include "hprof_error.h"178#include "hprof_util.h"179#include "hprof_blocks.h"180#include "hprof_stack.h"181#include "hprof_init.h"182#include "hprof_table.h"183#include "hprof_string.h"184#include "hprof_class.h"185#include "hprof_tracker.h"186#include "hprof_frame.h"187#include "hprof_monitor.h"188#include "hprof_trace.h"189#include "hprof_site.h"190#include "hprof_event.h"191#include "hprof_reference.h"192#include "hprof_object.h"193#include "hprof_loader.h"194#include "hprof_tls.h"195#include "hprof_check.h"196#include "hprof_io.h"197#include "hprof_listener.h"198#include "hprof_cpu.h"199#include "hprof_tag.h"200201/* Global data structure */202203struct LineTable;204205typedef struct {206207jvmtiEnv *jvmti; /* JVMTI env for this session */208JavaVM *jvm; /* JavaVM* for this session */209#ifndef SKIP_NPT210NptEnv *npt; /* NptEnv* for this session, see npt.h */211#endif212jint cachedJvmtiVersion; /* JVMTI version number */213214char *header; /* "JAVA PROFILE 1.0.[12]" */215jboolean segmented; /* JNI_TRUE if 1.0.2 */216jlong maxHeapSegment;217jlong maxMemory;218219/* Option settings */220char * options; /* option string copy */221char * utf8_output_filename;/* file=filename */222int net_port; /* net=hostname:port */223char * net_hostname; /* net=hostname:port */224char output_format; /* format=a|b */225int max_trace_depth; /* depth=max_trace_depth */226int prof_trace_depth; /* max_trace_depth or 2 (old) */227int sample_interval; /* interval=sample_interval (ms) */228double cutoff_point; /* cutoff=cutoff_point */229jboolean cpu_sampling; /* cpu=samples|y */230jboolean cpu_timing; /* cpu=times */231jboolean old_timing_format; /* cpu=old (old) output format */232jboolean heap_dump; /* heap=dump|all */233jboolean alloc_sites; /* heap=sites|all */234jboolean thread_in_traces; /* thread=y|n */235jboolean lineno_in_traces; /* lineno=y|n */236jboolean dump_on_exit; /* doe=y|n */237jboolean micro_state_accounting; /* msa=y|n */238jboolean force_output; /* force=y|n */239jboolean monitor_tracing; /* monitor=y|n */240jboolean gc_okay; /* gc_okay=y|n (Not used) */241242unsigned logflags; /* logflags=bitmask */243244#define DEBUGFLAG_UNPREPARED_CLASSES 0x001245unsigned debugflags; /* debugflags=bitmask */246247jboolean coredump; /* coredump=y|n */248jboolean errorexit; /* errorexit=y|n */249jboolean pause; /* pause=y|n */250jboolean debug; /* debug=y|n */251jboolean verbose; /* verbose=y|n */252jboolean primfields; /* primfields=y|n */253jboolean primarrays; /* primarrays=y|n */254jint experiment; /* X=NUMBER */255256int fd; /* file or socket (net=addr). */257jboolean socket; /* True if fd is a socket (net=addr). */258jboolean bci; /* True if any kind of BCI being done */259jboolean obj_watch; /* True if bci and watching allocs */260261int bci_counter; /* Class BCI counter */262263int heap_fd;264char *output_filename; /* file=filename */265char *heapfilename;266267int check_fd;268char *checkfilename;269270volatile jboolean dump_in_process; /* Dump in process */271volatile jboolean jvm_initializing; /* VMInit happening */272volatile jboolean jvm_initialized; /* VMInit happened */273volatile jboolean jvm_shut_down; /* VMDeath happened */274jboolean vm_death_callback_active; /* VMDeath happening */275276/* Stack of objects freed during GC */277Stack * object_free_stack;278jrawMonitorID object_free_lock;279280/* Lock for debug_malloc() */281jrawMonitorID debug_malloc_lock;282283/* Count of classes that JVMTI thinks are active */284jint class_count;285286/* Used to track callbacks for VM_DEATH */287jrawMonitorID callbackBlock;288jrawMonitorID callbackLock;289jint active_callbacks;290291/* Running totals on all bytes allocated */292jlong total_alloced_bytes;293jlong total_alloced_instances;294jint total_live_bytes;295jint total_live_instances;296297/* Running total on all time spent in GC (very rough estimate) */298jlong gc_start_time;299jlong time_in_gc;300301/* Global Data access Lock */302jrawMonitorID data_access_lock;303304/* Global Dump lock */305jrawMonitorID dump_lock;306307/* Milli-second clock when hprof onload started */308jlong micro_sec_ticks;309310/* Thread class (for starting agent threads) */311ClassIndex thread_cnum;312313/* Agent threads started information */314jboolean listener_loop_running;315jrawMonitorID listener_loop_lock;316jboolean cpu_loop_running;317jrawMonitorID cpu_loop_lock;318jrawMonitorID cpu_sample_lock; /* cpu=samples loop */319jint gc_finish; /* Count of GC finish events */320jboolean gc_finish_active; /* True if thread active */321jboolean gc_finish_stop_request; /* True if we want it to stop */322jrawMonitorID gc_finish_lock;323324jboolean pause_cpu_sampling; /* temp pause in cpu sampling */325326/* Output buffer, position, size, and position in dump if reading */327char * write_buffer;328int write_buffer_index;329int write_buffer_size;330char * heap_buffer;331int heap_buffer_index;332int heap_buffer_size;333jlong heap_last_tag_position;334jlong heap_write_count;335char * check_buffer;336int check_buffer_index;337int check_buffer_size;338339/* Serial number counters for tables (see hprof_table.c), classes,340* tls (thread local storage), and traces.341*/342SerialNumber table_serial_number_start;343SerialNumber class_serial_number_start;344SerialNumber thread_serial_number_start;345SerialNumber trace_serial_number_start;346SerialNumber object_serial_number_start;347SerialNumber frame_serial_number_start;348SerialNumber gref_serial_number_start;349350SerialNumber table_serial_number_counter;351SerialNumber class_serial_number_counter;352SerialNumber thread_serial_number_counter;353SerialNumber trace_serial_number_counter;354SerialNumber object_serial_number_counter;355SerialNumber frame_serial_number_counter;356SerialNumber gref_serial_number_counter;357358/* The methodID for the Object <init> method. */359jmethodID object_init_method;360361/* Keeping track of the tracker class and it's methods */362volatile jint tracking_engaged; /* !=0 means it's on */363ClassIndex tracker_cnum;364int tracker_method_count;365struct {366StringIndex name; /* String index for name */367StringIndex sig; /* String index for signature */368jmethodID method; /* Method ID */369} tracker_methods[12]; /* MAX 12 Tracker class methods */370371/* Index to some common items */372LoaderIndex system_loader;373SerialNumber unknown_thread_serial_num;374TraceIndex system_trace_index;375SiteIndex system_object_site_index;376jint system_class_size;377TraceIndex hprof_trace_index;378SiteIndex hprof_site_index;379380/* Tables for strings, classes, sites, etc. */381struct LookupTable * string_table;382struct LookupTable * ioname_table;383struct LookupTable * class_table;384struct LookupTable * site_table;385struct LookupTable * object_table;386struct LookupTable * reference_table;387struct LookupTable * frame_table;388struct LookupTable * trace_table;389struct LookupTable * monitor_table;390struct LookupTable * tls_table;391struct LookupTable * loader_table;392393/* Handles to java_crw_demo library */394void * java_crw_demo_library;395void * java_crw_demo_function;396void * java_crw_demo_classname_function;397398/* Indication that the agent has been loaded */399jboolean isLoaded;400401} GlobalData;402403/* This should be the only 'extern' in the library (not exported). */404405extern GlobalData * gdata;406407#endif408409410