0N/A/*
5539N/A * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A *
0N/A * Redistribution and use in source and binary forms, with or without
0N/A * modification, are permitted provided that the following conditions
0N/A * are met:
0N/A *
0N/A * - Redistributions of source code must retain the above copyright
0N/A * notice, this list of conditions and the following disclaimer.
0N/A *
0N/A * - Redistributions in binary form must reproduce the above copyright
0N/A * notice, this list of conditions and the following disclaimer in the
0N/A * documentation and/or other materials provided with the distribution.
0N/A *
2362N/A * - Neither the name of Oracle nor the names of its
0N/A * contributors may be used to endorse or promote products derived
0N/A * from this software without specific prior written permission.
0N/A *
0N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
0N/A * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
0N/A * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
0N/A * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0N/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0N/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0N/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0N/A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0N/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0N/A */
0N/A
4378N/A/*
4378N/A * This source code is provided to illustrate the usage of a given feature
4378N/A * or technique and has been deliberately simplified. Additional steps
4378N/A * required for a production-quality application, such as security checks,
4378N/A * input validation and proper error handling, might not be present in
4378N/A * this sample code.
4378N/A */
4378N/A
4378N/A
0N/A/* Primary hprof #include file, should be included by most if not
0N/A * all hprof source files. Gives access to the global data structure
0N/A * and all global macros, and everything declared in the #include
0N/A * files of each of the source files.
0N/A */
0N/A
0N/A#ifndef HPROF_H
0N/A#define HPROF_H
0N/A
0N/A/* Standard C functions used throughout. */
0N/A
0N/A#include <stdio.h>
0N/A#include <stdlib.h>
0N/A#include <ctype.h>
0N/A#include <string.h>
0N/A#include <stddef.h>
0N/A#include <stdarg.h>
0N/A#include <limits.h>
0N/A#include <time.h>
0N/A#include <errno.h>
0N/A
0N/A/* General JVM/Java functions, types and macros. */
0N/A
0N/A#include <sys/types.h>
0N/A#include "jni.h"
0N/A#include "jvmti.h"
0N/A#include "classfile_constants.h"
5539N/A#include "jvm_md.h"
0N/A
0N/A#ifndef SKIP_NPT
0N/A#include "npt.h" /* To get NptEnv for doing character conversions */
0N/A#endif
0N/A
0N/A/* Macros to extract the upper and lower 32 bits of a jlong */
0N/A
0N/A#define jlong_high(a) ((jint)((a)>>32))
0N/A#define jlong_low(a) ((jint)(a))
0N/A#define jlong_to_jint(a) ((jint)(a))
0N/A#define jint_to_jlong(a) ((jlong)(a))
0N/A
0N/A#define jlong_add(a, b) ((a) + (b))
0N/A
0N/A
0N/A/* The type used to contain a generic 32bit "serial number". */
0N/A
0N/Atypedef unsigned SerialNumber;
0N/A
0N/A/* How the options get to OnLoad: */
0N/A
0N/A#define AGENTNAME "hprof"
0N/A#define XRUN "-Xrun" AGENTNAME
0N/A#define AGENTLIB "-agentlib:" AGENTNAME
0N/A
0N/A/* Name of prelude file, found at runtime relative to java binary location */
0N/A
0N/A#define PRELUDE_FILE "jvm.hprof.txt"
0N/A
0N/A/* File I/O buffer size to be used with any file i/o operation */
0N/A
0N/A#define FILE_IO_BUFFER_SIZE (1024*64)
0N/A
0N/A/* Machine dependent functions. */
0N/A
0N/A#include "hprof_md.h"
0N/A
0N/A/* Table index types */
0N/A
0N/Atypedef unsigned TableIndex;
0N/Atypedef TableIndex ClassIndex;
0N/Atypedef TableIndex FrameIndex;
0N/Atypedef TableIndex IoNameIndex;
0N/Atypedef TableIndex MonitorIndex;
0N/Atypedef TableIndex ObjectIndex;
0N/Atypedef TableIndex LoaderIndex;
0N/Atypedef TableIndex RefIndex;
0N/Atypedef TableIndex SiteIndex;
0N/Atypedef TableIndex StringIndex;
0N/Atypedef TableIndex TlsIndex;
0N/Atypedef TableIndex TraceIndex;
0N/A
0N/A/* Index for method tables in classes */
0N/A
0N/Atypedef int MethodIndex;
0N/A
0N/A/* The different kinds of class status bits. */
0N/A
0N/Aenum ClassStatus {
0N/A CLASS_PREPARED = 0x00000001,
0N/A CLASS_LOADED = 0x00000002,
0N/A CLASS_UNLOADED = 0x00000004,
0N/A CLASS_SPECIAL = 0x00000008,
0N/A CLASS_IN_LOAD_LIST = 0x00000010,
0N/A CLASS_SYSTEM = 0x00000020,
0N/A CLASS_DUMPED = 0x00000040
0N/A};
0N/Atypedef jint ClassStatus;
0N/A
0N/A/* The different kind of objects we track with heap=dump */
0N/A
0N/Atypedef unsigned char ObjectKind;
0N/Aenum {
0N/A OBJECT_NORMAL = 1,
0N/A OBJECT_CLASS = 2,
0N/A OBJECT_SYSTEM = 3,
0N/A OBJECT_HPROF = 4,
0N/A OBJECT_LOADER = 5
0N/A};
0N/A
0N/A/* Used by site_write() when writing out the heap=sites data. */
0N/A
0N/Aenum {
0N/A SITE_DUMP_INCREMENTAL = 0x01,
0N/A SITE_SORT_BY_ALLOC = 0x02,
0N/A SITE_FORCE_GC = 0x04
0N/A};
0N/A
0N/A/* Used to hold information about a field, and potentially a value too. */
0N/A
0N/Atypedef struct FieldInfo {
0N/A ClassIndex cnum;
0N/A StringIndex name_index;
0N/A StringIndex sig_index;
0N/A unsigned short modifiers;
0N/A unsigned char primType;
0N/A unsigned char primSize;
0N/A} FieldInfo;
0N/A
0N/A/* Used to hold information about a constant pool entry value for a class. */
0N/A
0N/Atypedef struct ConstantPoolValue {
0N/A unsigned constant_pool_index;
0N/A StringIndex sig_index;
0N/A jvalue value;
0N/A} ConstantPoolValue;
0N/A
0N/A/* All machine independent functions */
0N/A
0N/A#include "hprof_error.h"
0N/A#include "hprof_util.h"
0N/A#include "hprof_blocks.h"
0N/A#include "hprof_stack.h"
0N/A#include "hprof_init.h"
0N/A#include "hprof_table.h"
0N/A#include "hprof_string.h"
0N/A#include "hprof_class.h"
0N/A#include "hprof_tracker.h"
0N/A#include "hprof_frame.h"
0N/A#include "hprof_monitor.h"
0N/A#include "hprof_trace.h"
0N/A#include "hprof_site.h"
0N/A#include "hprof_event.h"
0N/A#include "hprof_reference.h"
0N/A#include "hprof_object.h"
0N/A#include "hprof_loader.h"
0N/A#include "hprof_tls.h"
0N/A#include "hprof_check.h"
0N/A#include "hprof_io.h"
0N/A#include "hprof_listener.h"
0N/A#include "hprof_cpu.h"
0N/A#include "hprof_tag.h"
0N/A
0N/A/* Global data structure */
0N/A
0N/Astruct LineTable;
0N/A
0N/Atypedef struct {
0N/A
0N/A jvmtiEnv *jvmti; /* JVMTI env for this session */
0N/A JavaVM *jvm; /* JavaVM* for this session */
0N/A#ifndef SKIP_NPT
0N/A NptEnv *npt; /* NptEnv* for this session, see npt.h */
0N/A#endif
0N/A jint cachedJvmtiVersion; /* JVMTI version number */
0N/A
0N/A char *header; /* "JAVA PROFILE 1.0.[12]" */
0N/A jboolean segmented; /* JNI_TRUE if 1.0.2 */
0N/A jlong maxHeapSegment;
0N/A jlong maxMemory;
0N/A
0N/A /* Option settings */
0N/A char * options; /* option string copy */
0N/A char * utf8_output_filename;/* file=filename */
0N/A int net_port; /* net=hostname:port */
0N/A char * net_hostname; /* net=hostname:port */
0N/A char output_format; /* format=a|b */
0N/A int max_trace_depth; /* depth=max_trace_depth */
0N/A int prof_trace_depth; /* max_trace_depth or 2 (old) */
0N/A int sample_interval; /* interval=sample_interval (ms) */
0N/A double cutoff_point; /* cutoff=cutoff_point */
0N/A jboolean cpu_sampling; /* cpu=samples|y */
0N/A jboolean cpu_timing; /* cpu=times */
0N/A jboolean old_timing_format; /* cpu=old (old) output format */
0N/A jboolean heap_dump; /* heap=dump|all */
0N/A jboolean alloc_sites; /* heap=sites|all */
0N/A jboolean thread_in_traces; /* thread=y|n */
0N/A jboolean lineno_in_traces; /* lineno=y|n */
0N/A jboolean dump_on_exit; /* doe=y|n */
0N/A jboolean micro_state_accounting; /* msa=y|n */
0N/A jboolean force_output; /* force=y|n */
0N/A jboolean monitor_tracing; /* monitor=y|n */
0N/A jboolean gc_okay; /* gc_okay=y|n (Not used) */
0N/A
0N/A unsigned logflags; /* logflags=bitmask */
0N/A
0N/A #define DEBUGFLAG_UNPREPARED_CLASSES 0x001
0N/A unsigned debugflags; /* debugflags=bitmask */
0N/A
0N/A jboolean coredump; /* coredump=y|n */
0N/A jboolean errorexit; /* errorexit=y|n */
0N/A jboolean pause; /* pause=y|n */
0N/A jboolean debug; /* debug=y|n */
0N/A jboolean verbose; /* verbose=y|n */
0N/A jboolean primfields; /* primfields=y|n */
0N/A jboolean primarrays; /* primarrays=y|n */
0N/A jint experiment; /* X=NUMBER */
0N/A
0N/A int fd; /* file or socket (net=addr). */
0N/A jboolean socket; /* True if fd is a socket (net=addr). */
0N/A jboolean bci; /* True if any kind of BCI being done */
0N/A jboolean obj_watch; /* True if bci and watching allocs */
0N/A
0N/A int bci_counter; /* Class BCI counter */
0N/A
0N/A int heap_fd;
0N/A char *output_filename; /* file=filename */
0N/A char *heapfilename;
0N/A
0N/A int check_fd;
0N/A char *checkfilename;
0N/A
0N/A volatile jboolean dump_in_process; /* Dump in process */
0N/A volatile jboolean jvm_initializing; /* VMInit happening */
0N/A volatile jboolean jvm_initialized; /* VMInit happened */
0N/A volatile jboolean jvm_shut_down; /* VMDeath happened */
0N/A jboolean vm_death_callback_active; /* VMDeath happening */
0N/A
0N/A /* Stack of objects freed during GC */
0N/A Stack * object_free_stack;
0N/A jrawMonitorID object_free_lock;
0N/A
0N/A /* Lock for debug_malloc() */
0N/A jrawMonitorID debug_malloc_lock;
0N/A
0N/A /* Count of classes that JVMTI thinks are active */
0N/A jint class_count;
0N/A
0N/A /* Used to track callbacks for VM_DEATH */
0N/A jrawMonitorID callbackBlock;
0N/A jrawMonitorID callbackLock;
0N/A jint active_callbacks;
0N/A
0N/A /* Running totals on all bytes allocated */
0N/A jlong total_alloced_bytes;
0N/A jlong total_alloced_instances;
0N/A jint total_live_bytes;
0N/A jint total_live_instances;
0N/A
0N/A /* Running total on all time spent in GC (very rough estimate) */
0N/A jlong gc_start_time;
0N/A jlong time_in_gc;
0N/A
0N/A /* Global Data access Lock */
0N/A jrawMonitorID data_access_lock;
0N/A
0N/A /* Global Dump lock */
0N/A jrawMonitorID dump_lock;
0N/A
0N/A /* Milli-second clock when hprof onload started */
0N/A jlong micro_sec_ticks;
0N/A
0N/A /* Thread class (for starting agent threads) */
0N/A ClassIndex thread_cnum;
0N/A
0N/A /* Agent threads started information */
0N/A jboolean listener_loop_running;
0N/A jrawMonitorID listener_loop_lock;
0N/A jboolean cpu_loop_running;
0N/A jrawMonitorID cpu_loop_lock;
0N/A jrawMonitorID cpu_sample_lock; /* cpu=samples loop */
0N/A jint gc_finish; /* Count of GC finish events */
0N/A jboolean gc_finish_active; /* True if thread active */
0N/A jboolean gc_finish_stop_request; /* True if we want it to stop */
0N/A jrawMonitorID gc_finish_lock;
0N/A
0N/A jboolean pause_cpu_sampling; /* temp pause in cpu sampling */
0N/A
0N/A /* Output buffer, position, size, and position in dump if reading */
0N/A char * write_buffer;
0N/A int write_buffer_index;
0N/A int write_buffer_size;
0N/A char * heap_buffer;
0N/A int heap_buffer_index;
0N/A int heap_buffer_size;
0N/A jlong heap_last_tag_position;
0N/A jlong heap_write_count;
0N/A char * check_buffer;
0N/A int check_buffer_index;
0N/A int check_buffer_size;
0N/A
0N/A /* Serial number counters for tables (see hprof_table.c), classes,
0N/A * tls (thread local storage), and traces.
0N/A */
0N/A SerialNumber table_serial_number_start;
0N/A SerialNumber class_serial_number_start;
0N/A SerialNumber thread_serial_number_start;
0N/A SerialNumber trace_serial_number_start;
0N/A SerialNumber object_serial_number_start;
0N/A SerialNumber frame_serial_number_start;
0N/A SerialNumber gref_serial_number_start;
0N/A
0N/A SerialNumber table_serial_number_counter;
0N/A SerialNumber class_serial_number_counter;
0N/A SerialNumber thread_serial_number_counter;
0N/A SerialNumber trace_serial_number_counter;
0N/A SerialNumber object_serial_number_counter;
0N/A SerialNumber frame_serial_number_counter;
0N/A SerialNumber gref_serial_number_counter;
0N/A
0N/A /* The methodID for the Object <init> method. */
0N/A jmethodID object_init_method;
0N/A
0N/A /* Keeping track of the tracker class and it's methods */
0N/A volatile jint tracking_engaged; /* !=0 means it's on */
0N/A ClassIndex tracker_cnum;
0N/A int tracker_method_count;
0N/A struct {
0N/A StringIndex name; /* String index for name */
0N/A StringIndex sig; /* String index for signature */
0N/A jmethodID method; /* Method ID */
0N/A } tracker_methods[12]; /* MAX 12 Tracker class methods */
0N/A
0N/A /* Index to some common items */
0N/A LoaderIndex system_loader;
0N/A SerialNumber unknown_thread_serial_num;
0N/A TraceIndex system_trace_index;
0N/A SiteIndex system_object_site_index;
0N/A jint system_class_size;
0N/A TraceIndex hprof_trace_index;
0N/A SiteIndex hprof_site_index;
0N/A
0N/A /* Tables for strings, classes, sites, etc. */
0N/A struct LookupTable * string_table;
0N/A struct LookupTable * ioname_table;
0N/A struct LookupTable * class_table;
0N/A struct LookupTable * site_table;
0N/A struct LookupTable * object_table;
0N/A struct LookupTable * reference_table;
0N/A struct LookupTable * frame_table;
0N/A struct LookupTable * trace_table;
0N/A struct LookupTable * monitor_table;
0N/A struct LookupTable * tls_table;
0N/A struct LookupTable * loader_table;
0N/A
0N/A /* Handles to java_crw_demo library */
0N/A void * java_crw_demo_library;
0N/A void * java_crw_demo_function;
0N/A void * java_crw_demo_classname_function;
0N/A
0N/A /* Indication that the agent has been loaded */
0N/A jboolean isLoaded;
0N/A
0N/A} GlobalData;
0N/A
0N/A/* This should be the only 'extern' in the library (not exported). */
0N/A
0N/Aextern GlobalData * gdata;
0N/A
0N/A#endif