hotspot/src/share/vm/services/heapDumper.cpp
author jprovino
Mon, 04 Apr 2016 12:57:48 -0400
changeset 37248 11a660dbbb8e
parent 37113 5a33bf5089ac
child 46329 53ccc37bda19
permissions -rw-r--r--
8132524: Missing includes to resourceArea.hpp Summary: Files that use ResourceMark are missing the include of resourceArea.hpp Reviewed-by: tschatzl, jwilhelm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
     2
 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6445
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6445
diff changeset
    26
#include "classfile/symbolTable.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6445
diff changeset
    27
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6445
diff changeset
    28
#include "classfile/vmSymbols.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29697
diff changeset
    29
#include "gc/shared/gcLocker.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29697
diff changeset
    30
#include "gc/shared/genCollectedHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29697
diff changeset
    31
#include "gc/shared/vmGCOperations.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 37113
diff changeset
    32
#include "memory/resourceArea.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6445
diff changeset
    33
#include "memory/universe.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6445
diff changeset
    34
#include "oops/objArrayKlass.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 27880
diff changeset
    35
#include "oops/objArrayOop.inline.hpp"
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 27880
diff changeset
    36
#include "oops/oop.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6445
diff changeset
    37
#include "runtime/javaCalls.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6445
diff changeset
    38
#include "runtime/jniHandles.hpp"
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 24424
diff changeset
    39
#include "runtime/os.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6445
diff changeset
    40
#include "runtime/reflectionUtils.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6445
diff changeset
    41
#include "runtime/vframe.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6445
diff changeset
    42
#include "runtime/vmThread.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6445
diff changeset
    43
#include "runtime/vm_operations.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6445
diff changeset
    44
#include "services/heapDumper.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6445
diff changeset
    45
#include "services/threadService.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29697
diff changeset
    46
#include "utilities/macros.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6445
diff changeset
    47
#include "utilities/ostream.hpp"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14488
diff changeset
    48
#if INCLUDE_ALL_GCS
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29697
diff changeset
    49
#include "gc/parallel/parallelScavengeHeap.hpp"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14488
diff changeset
    50
#endif // INCLUDE_ALL_GCS
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
 * HPROF binary format - description copied from:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
 *   src/share/demo/jvmti/hprof/hprof_io.c
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
 *
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
    57
 *  header    "JAVA PROFILE 1.0.2" (0-terminated)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
 *  u4        size of identifiers. Identifiers are used to represent
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
 *            UTF8 strings, objects, stack traces, etc. They usually
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
 *            have the same size as host pointers. For example, on
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
 *            Solaris and Win32, the size is 4.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
 * u4         high word
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
 * u4         low word    number of milliseconds since 0:00 GMT, 1/1/70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
 * [record]*  a sequence of records.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
 * Record format:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
 * u1         a TAG denoting the type of the record
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
 * u4         number of *microseconds* since the time stamp in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
 *            header. (wraps around in a little more than an hour)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
 * u4         number of bytes *remaining* in the record. Note that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
 *            this number excludes the tag and the length field itself.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
 * [u1]*      BODY of the record (a sequence of bytes)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
 * The following TAGs are supported:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
 * TAG           BODY       notes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
 *----------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
 * HPROF_UTF8               a UTF8-encoded name
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
 *               id         name ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
 *               [u1]*      UTF8 characters (no trailing zero)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
 * HPROF_LOAD_CLASS         a newly loaded class
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
 *                u4        class serial number (> 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
 *                id        class object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
 *                u4        stack trace serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
 *                id        class name ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
 * HPROF_UNLOAD_CLASS       an unloading class
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
 *                u4        class serial_number
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
 * HPROF_FRAME              a Java stack frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
 *                id        stack frame ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
 *                id        method name ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
 *                id        method signature ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
 *                id        source file name ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
 *                u4        class serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
 *                i4        line number. >0: normal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
 *                                       -1: unknown
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
 *                                       -2: compiled method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
 *                                       -3: native method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
 * HPROF_TRACE              a Java stack trace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
 *               u4         stack trace serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
 *               u4         thread serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
 *               u4         number of frames
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
 *               [id]*      stack frame IDs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
 * HPROF_ALLOC_SITES        a set of heap allocation sites, obtained after GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
 *               u2         flags 0x0001: incremental vs. complete
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
 *                                0x0002: sorted by allocation vs. live
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
 *                                0x0004: whether to force a GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
 *               u4         cutoff ratio
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
 *               u4         total live bytes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
 *               u4         total live instances
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
 *               u8         total bytes allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
 *               u8         total instances allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
 *               u4         number of sites that follow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
 *               [u1        is_array: 0:  normal object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
 *                                    2:  object array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
 *                                    4:  boolean array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
 *                                    5:  char array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
 *                                    6:  float array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
 *                                    7:  double array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
 *                                    8:  byte array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
 *                                    9:  short array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
 *                                    10: int array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
 *                                    11: long array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
 *                u4        class serial number (may be zero during startup)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
 *                u4        stack trace serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
 *                u4        number of bytes alive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
 *                u4        number of instances alive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
 *                u4        number of bytes allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
 *                u4]*      number of instance allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
 * HPROF_START_THREAD       a newly started thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
 *               u4         thread serial number (> 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
 *               id         thread object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
 *               u4         stack trace serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
 *               id         thread name ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
 *               id         thread group name ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
 *               id         thread group parent name ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
 * HPROF_END_THREAD         a terminating thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
 *               u4         thread serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
 * HPROF_HEAP_SUMMARY       heap summary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
 *               u4         total live bytes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
 *               u4         total live instances
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
 *               u8         total bytes allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
 *               u8         total instances allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
 * HPROF_HEAP_DUMP          denote a heap dump
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
 *               [heap dump sub-records]*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
 *                          There are four kinds of heap dump sub-records:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
 *               u1         sub-record type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
 *               HPROF_GC_ROOT_UNKNOWN         unknown root
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
 *                          id         object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
 *               HPROF_GC_ROOT_THREAD_OBJ      thread object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
 *                          id         thread object ID  (may be 0 for a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
 *                                     thread newly attached through JNI)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
 *                          u4         thread sequence number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
 *                          u4         stack trace sequence number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
 *               HPROF_GC_ROOT_JNI_GLOBAL      JNI global ref root
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
 *                          id         object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
 *                          id         JNI global ref ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
 *               HPROF_GC_ROOT_JNI_LOCAL       JNI local ref
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
 *                          id         object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
 *                          u4         thread serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
 *                          u4         frame # in stack trace (-1 for empty)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
 *               HPROF_GC_ROOT_JAVA_FRAME      Java stack frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
 *                          id         object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
 *                          u4         thread serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
 *                          u4         frame # in stack trace (-1 for empty)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
 *               HPROF_GC_ROOT_NATIVE_STACK    Native stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
 *                          id         object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
 *                          u4         thread serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
 *               HPROF_GC_ROOT_STICKY_CLASS    System class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
 *                          id         object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
 *               HPROF_GC_ROOT_THREAD_BLOCK    Reference from thread block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
 *                          id         object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
 *                          u4         thread serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
 *               HPROF_GC_ROOT_MONITOR_USED    Busy monitor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
 *                          id         object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
 *               HPROF_GC_CLASS_DUMP           dump of a class object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
 *                          id         class object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
 *                          u4         stack trace serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
 *                          id         super class object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
 *                          id         class loader object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
 *                          id         signers object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
 *                          id         protection domain object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
 *                          id         reserved
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
 *                          id         reserved
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
 *                          u4         instance size (in bytes)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
 *                          u2         size of constant pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
 *                          [u2,       constant pool index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
 *                           ty,       type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
 *                                     2:  object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
 *                                     4:  boolean
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
 *                                     5:  char
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
 *                                     6:  float
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
 *                                     7:  double
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
 *                                     8:  byte
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
 *                                     9:  short
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
 *                                     10: int
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
 *                                     11: long
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
 *                           vl]*      and value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
 *                          u2         number of static fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
 *                          [id,       static field name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
 *                           ty,       type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
 *                           vl]*      and value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
 *                          u2         number of inst. fields (not inc. super)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
 *                          [id,       instance field name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
 *                           ty]*      type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
 *               HPROF_GC_INSTANCE_DUMP        dump of a normal object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
 *                          id         object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
 *                          u4         stack trace serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
 *                          id         class object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
 *                          u4         number of bytes that follow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
 *                          [vl]*      instance field values (class, followed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
 *                                     by super, super's super ...)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
 *               HPROF_GC_OBJ_ARRAY_DUMP       dump of an object array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
 *                          id         array object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
 *                          u4         stack trace serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
 *                          u4         number of elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
 *                          id         array class ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
 *                          [id]*      elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
 *               HPROF_GC_PRIM_ARRAY_DUMP      dump of a primitive array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
 *                          id         array object ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
 *                          u4         stack trace serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
 *                          u4         number of elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
 *                          u1         element type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
 *                                     4:  boolean array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
 *                                     5:  char array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
 *                                     6:  float array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
 *                                     7:  double array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
 *                                     8:  byte array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
 *                                     9:  short array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
 *                                     10: int array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
 *                                     11: long array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
 *                          [u1]*      elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
 * HPROF_CPU_SAMPLES        a set of sample traces of running threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
 *                u4        total number of samples
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
 *                u4        # of traces
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
 *               [u4        # of samples
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
 *                u4]*      stack trace serial number
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
 * HPROF_CONTROL_SETTINGS   the settings of on/off switches
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
 *                u4        0x00000001: alloc traces on/off
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
 *                          0x00000002: cpu sampling on/off
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
 *                u2        stack trace depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
 * When the header is "JAVA PROFILE 1.0.2" a heap dump can optionally
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
 * be generated as a sequence of heap dump segments. This sequence is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
 * terminated by an end record. The additional tags allowed by format
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
 * "JAVA PROFILE 1.0.2" are:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
 * HPROF_HEAP_DUMP_SEGMENT  denote a heap dump segment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
 *               [heap dump sub-records]*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
 *               The same sub-record types allowed by HPROF_HEAP_DUMP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
 * HPROF_HEAP_DUMP_END      denotes the end of a heap dump
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
// HPROF tags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
typedef enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  // top-level records
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  HPROF_UTF8                    = 0x01,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  HPROF_LOAD_CLASS              = 0x02,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  HPROF_UNLOAD_CLASS            = 0x03,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  HPROF_FRAME                   = 0x04,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  HPROF_TRACE                   = 0x05,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  HPROF_ALLOC_SITES             = 0x06,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  HPROF_HEAP_SUMMARY            = 0x07,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  HPROF_START_THREAD            = 0x0A,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  HPROF_END_THREAD              = 0x0B,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  HPROF_HEAP_DUMP               = 0x0C,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  HPROF_CPU_SAMPLES             = 0x0D,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  HPROF_CONTROL_SETTINGS        = 0x0E,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  // 1.0.2 record types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  HPROF_HEAP_DUMP_SEGMENT       = 0x1C,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  HPROF_HEAP_DUMP_END           = 0x2C,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  // field types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  HPROF_ARRAY_OBJECT            = 0x01,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  HPROF_NORMAL_OBJECT           = 0x02,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  HPROF_BOOLEAN                 = 0x04,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  HPROF_CHAR                    = 0x05,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  HPROF_FLOAT                   = 0x06,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  HPROF_DOUBLE                  = 0x07,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  HPROF_BYTE                    = 0x08,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  HPROF_SHORT                   = 0x09,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  HPROF_INT                     = 0x0A,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  HPROF_LONG                    = 0x0B,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  // data-dump sub-records
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  HPROF_GC_ROOT_UNKNOWN         = 0xFF,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  HPROF_GC_ROOT_JNI_GLOBAL      = 0x01,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  HPROF_GC_ROOT_JNI_LOCAL       = 0x02,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  HPROF_GC_ROOT_JAVA_FRAME      = 0x03,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  HPROF_GC_ROOT_NATIVE_STACK    = 0x04,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  HPROF_GC_ROOT_STICKY_CLASS    = 0x05,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  HPROF_GC_ROOT_THREAD_BLOCK    = 0x06,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  HPROF_GC_ROOT_MONITOR_USED    = 0x07,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  HPROF_GC_ROOT_THREAD_OBJ      = 0x08,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  HPROF_GC_CLASS_DUMP           = 0x20,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  HPROF_GC_INSTANCE_DUMP        = 0x21,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  HPROF_GC_OBJ_ARRAY_DUMP       = 0x22,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  HPROF_GC_PRIM_ARRAY_DUMP      = 0x23
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
} hprofTag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
// Default stack trace ID (used for dummy HPROF_TRACE record)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
enum {
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
   369
  STACK_TRACE_ID = 1,
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
   370
  INITIAL_CLASS_COUNT = 200
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
// Supports I/O operations on a dump file
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
class DumpWriter : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    io_buffer_size  = 8*M
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  int _fd;              // file descriptor (-1 if dump file not open)
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   382
  julong _bytes_written; // number of byte written to dump file
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  char* _buffer;    // internal buffer
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   385
  size_t _size;
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   386
  size_t _pos;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   388
  jlong _dump_start;
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   389
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  char* _error;   // error message when I/O fails
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  void set_file_descriptor(int fd)              { _fd = fd; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  int file_descriptor() const                   { return _fd; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  char* buffer() const                          { return _buffer; }
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   396
  size_t buffer_size() const                    { return _size; }
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   397
  size_t position() const                       { return _pos; }
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   398
  void set_position(size_t pos)                 { _pos = pos; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  void set_error(const char* error)             { _error = (char*)os::strdup(error); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  // all I/O go through this function
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   403
  void write_internal(void* s, size_t len);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  DumpWriter(const char* path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  ~DumpWriter();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  void close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  bool is_open() const                  { return file_descriptor() >= 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  void flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   413
  jlong dump_start() const                      { return _dump_start; }
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   414
  void set_dump_start(jlong pos);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   415
  julong current_record_length();
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   416
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  // total number of bytes written to the disk
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   418
  julong bytes_written() const          { return _bytes_written; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  // adjust the number of bytes written to disk (used to keep the count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  // of the number of bytes written in case of rewrites)
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   422
  void adjust_bytes_written(jlong n)    { _bytes_written += n; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  // number of (buffered) bytes as yet unwritten to the dump file
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   425
  size_t bytes_unwritten() const        { return position(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  char* error() const                   { return _error; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  jlong current_offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  void seek_to_offset(jlong pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  // writer functions
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   433
  void write_raw(void* s, size_t len);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  void write_u1(u1 x)                   { write_raw((void*)&x, 1); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  void write_u2(u2 x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  void write_u4(u4 x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  void write_u8(u8 x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  void write_objectID(oop o);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   439
  void write_symbolID(Symbol* o);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  void write_classID(Klass* k);
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
   441
  void write_id(u4 x);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
DumpWriter::DumpWriter(const char* path) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  // try to allocate an I/O buffer of io_buffer_size. If there isn't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  // sufficient memory then reduce size until we can allocate something.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  _size = io_buffer_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  do {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11000
diff changeset
   449
    _buffer = (char*)os::malloc(_size, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    if (_buffer == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
      _size = _size >> 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  } while (_buffer == NULL && _size > 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  assert((_size > 0 && _buffer != NULL) || (_size == 0 && _buffer == NULL), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  _pos = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  _error = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  _bytes_written = 0L;
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   458
  _dump_start = (jlong)-1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  _fd = os::create_binary_file(path, false);    // don't replace existing file
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  // if the open failed we record the error
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  if (_fd < 0) {
37113
5a33bf5089ac 8148425: strerror() function is not thread-safe
stuefe
parents: 36375
diff changeset
   463
    _error = (char*)os::strdup(os::strerror(errno));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
DumpWriter::~DumpWriter() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  // flush and close dump file
7914
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
   469
  if (is_open()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  if (_buffer != NULL) os::free(_buffer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  if (_error != NULL) os::free(_error);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
// closes dump file (if open)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
void DumpWriter::close() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  // flush and close dump file
7914
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
   479
  if (is_open()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    flush();
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   481
    os::close(file_descriptor());
7914
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
   482
    set_file_descriptor(-1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   486
// sets the dump starting position
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   487
void DumpWriter::set_dump_start(jlong pos) {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   488
  _dump_start = pos;
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   489
}
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   490
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   491
julong DumpWriter::current_record_length() {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   492
  if (is_open()) {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   493
    // calculate the size of the dump record
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   494
    julong dump_end = bytes_written() + bytes_unwritten();
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   495
    assert(dump_end == (size_t)current_offset(), "checking");
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   496
    julong dump_len = dump_end - dump_start() - 4;
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   497
    return dump_len;
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   498
  }
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   499
  return 0;
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   500
}
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   501
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
// write directly to the file
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   503
void DumpWriter::write_internal(void* s, size_t len) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  if (is_open()) {
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   505
    const char* pos = (char*)s;
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   506
    ssize_t n = 0;
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   507
    while (len > 0) {
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   508
      uint tmp = (uint)MIN2(len, (size_t)UINT_MAX);
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   509
      n = os::write(file_descriptor(), pos, tmp);
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   510
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   511
      if (n < 0) {
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   512
        // EINTR cannot happen here, os::write will take care of that
37113
5a33bf5089ac 8148425: strerror() function is not thread-safe
stuefe
parents: 36375
diff changeset
   513
        set_error(os::strerror(errno));
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   514
        os::close(file_descriptor());
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   515
        set_file_descriptor(-1);
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   516
        return;
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   517
      }
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   518
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
      _bytes_written += n;
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   520
      pos += n;
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   521
      len -= n;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
// write raw bytes
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   527
void DumpWriter::write_raw(void* s, size_t len) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  if (is_open()) {
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   529
    // flush buffer to make room
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   530
    if ((position() + len) >= buffer_size()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
      flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
    // buffer not available or too big to buffer it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
    if ((buffer() == NULL) || (len >= buffer_size())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
      write_internal(s, len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
      // Should optimize this for u1/u2/u4/u8 sizes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
      memcpy(buffer() + position(), s, len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
      set_position(position() + len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
// flush any buffered bytes to the file
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
void DumpWriter::flush() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  if (is_open() && position() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    write_internal(buffer(), position());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
    set_position(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
jlong DumpWriter::current_offset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  if (is_open()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
    // the offset is the file offset plus whatever we have buffered
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    jlong offset = os::current_file_offset(file_descriptor());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
    assert(offset >= 0, "lseek failed");
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   558
    return offset + position();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    return (jlong)-1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
void DumpWriter::seek_to_offset(jlong off) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  assert(off >= 0, "bad offset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  // need to flush before seeking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  // may be closed due to I/O error
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  if (is_open()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
    jlong n = os::seek_to_file_offset(file_descriptor(), off);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
    assert(n >= 0, "lseek failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
void DumpWriter::write_u2(u2 x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  u2 v;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  Bytes::put_Java_u2((address)&v, x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  write_raw((void*)&v, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
void DumpWriter::write_u4(u4 x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  u4 v;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  Bytes::put_Java_u4((address)&v, x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  write_raw((void*)&v, 4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
void DumpWriter::write_u8(u8 x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  u8 v;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  Bytes::put_Java_u8((address)&v, x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  write_raw((void*)&v, 8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
void DumpWriter::write_objectID(oop o) {
20282
7f9cbdf89af2 7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents: 15483
diff changeset
   596
  address a = (address)o;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  write_u8((u8)a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  write_u4((u4)a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   604
void DumpWriter::write_symbolID(Symbol* s) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   605
  address a = (address)((uintptr_t)s);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   606
#ifdef _LP64
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   607
  write_u8((u8)a);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   608
#else
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   609
  write_u4((u4)a);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   610
#endif
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   611
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   612
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
   613
void DumpWriter::write_id(u4 x) {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
   614
#ifdef _LP64
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
   615
  write_u8((u8) x);
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
   616
#else
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
   617
  write_u4(x);
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
   618
#endif
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
   619
}
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
   620
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
// We use java mirror as the class ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
void DumpWriter::write_classID(Klass* k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  write_objectID(k->java_mirror());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
// Support class with a collection of functions used when dumping the heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
class DumperSupport : AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  // write a header of the given type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  static void write_header(DumpWriter* writer, hprofTag tag, u4 len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  // returns hprof tag for the given type signature
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   637
  static hprofTag sig2tag(Symbol* sig);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  // returns hprof tag for the given basic type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  static hprofTag type2tag(BasicType type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  // returns the size of the instance of the given class
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   642
  static u4 instance_size(Klass* k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
  // dump a jfloat
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
  static void dump_float(DumpWriter* writer, jfloat f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
  // dump a jdouble
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  static void dump_double(DumpWriter* writer, jdouble d);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
  // dumps the raw value of the given field
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  static void dump_field_value(DumpWriter* writer, char type, address addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  // dumps static fields of the given class
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   651
  static void dump_static_fields(DumpWriter* writer, Klass* k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  // dump the raw values of the instance fields of the given object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  static void dump_instance_fields(DumpWriter* writer, oop o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  // dumps the definition of the instance fields for a given class
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   655
  static void dump_instance_field_descriptors(DumpWriter* writer, Klass* k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  // creates HPROF_GC_INSTANCE_DUMP record for the given object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  static void dump_instance(DumpWriter* writer, oop o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  // creates HPROF_GC_CLASS_DUMP record for the given class and each of its
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  // array classes
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   660
  static void dump_class_and_array_classes(DumpWriter* writer, Klass* k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
  // creates HPROF_GC_CLASS_DUMP record for a given primitive array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  // class (and each multi-dimensional array class too)
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   663
  static void dump_basic_type_array_class(DumpWriter* writer, Klass* k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  // creates HPROF_GC_OBJ_ARRAY_DUMP record for the given object array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  static void dump_object_array(DumpWriter* writer, objArrayOop array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
  // creates HPROF_GC_PRIM_ARRAY_DUMP record for the given type array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  static void dump_prim_array(DumpWriter* writer, typeArrayOop array);
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
   669
  // create HPROF_FRAME record for the given method and bci
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   670
  static void dump_stack_frame(DumpWriter* writer, int frame_serial_num, int class_serial_num, Method* m, int bci);
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   671
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   672
  // check if we need to truncate an array
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   673
  static int calculate_array_max_length(DumpWriter* writer, arrayOop array, short header_size);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   674
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   675
  // writes a HPROF_HEAP_DUMP_SEGMENT record
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   676
  static void write_dump_header(DumpWriter* writer);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   677
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   678
  // fixes up the length of the current dump record
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   679
  static void write_current_dump_record_length(DumpWriter* writer);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   680
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   681
  // fixes up the current dump record and writes HPROF_HEAP_DUMP_END record
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
   682
  static void end_of_dump(DumpWriter* writer);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
// write a header of the given type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
void DumperSupport:: write_header(DumpWriter* writer, hprofTag tag, u4 len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  writer->write_u1((u1)tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  writer->write_u4(0);                  // current ticks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  writer->write_u4(len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
// returns hprof tag for the given type signature
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   693
hprofTag DumperSupport::sig2tag(Symbol* sig) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  switch (sig->byte_at(0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
    case JVM_SIGNATURE_CLASS    : return HPROF_NORMAL_OBJECT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
    case JVM_SIGNATURE_ARRAY    : return HPROF_NORMAL_OBJECT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
    case JVM_SIGNATURE_BYTE     : return HPROF_BYTE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
    case JVM_SIGNATURE_CHAR     : return HPROF_CHAR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
    case JVM_SIGNATURE_FLOAT    : return HPROF_FLOAT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
    case JVM_SIGNATURE_DOUBLE   : return HPROF_DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
    case JVM_SIGNATURE_INT      : return HPROF_INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
    case JVM_SIGNATURE_LONG     : return HPROF_LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
    case JVM_SIGNATURE_SHORT    : return HPROF_SHORT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
    case JVM_SIGNATURE_BOOLEAN  : return HPROF_BOOLEAN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
    default : ShouldNotReachHere(); /* to shut up compiler */ return HPROF_BYTE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
hprofTag DumperSupport::type2tag(BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
    case T_BYTE     : return HPROF_BYTE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
    case T_CHAR     : return HPROF_CHAR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
    case T_FLOAT    : return HPROF_FLOAT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
    case T_DOUBLE   : return HPROF_DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
    case T_INT      : return HPROF_INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
    case T_LONG     : return HPROF_LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
    case T_SHORT    : return HPROF_SHORT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
    case T_BOOLEAN  : return HPROF_BOOLEAN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
    default : ShouldNotReachHere(); /* to shut up compiler */ return HPROF_BYTE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
// dump a jfloat
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
void DumperSupport::dump_float(DumpWriter* writer, jfloat f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
  if (g_isnan(f)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
    writer->write_u4(0x7fc00000);    // collapsing NaNs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
    union {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
      int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
      float f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
    } u;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
    u.f = (float)f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
    writer->write_u4((u4)u.i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
// dump a jdouble
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
void DumperSupport::dump_double(DumpWriter* writer, jdouble d) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  union {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
    jlong l;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
    double d;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  } u;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
  if (g_isnan(d)) {                 // collapsing NaNs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
    u.l = (jlong)(0x7ff80000);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
    u.l = (u.l << 32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
    u.d = (double)d;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
  writer->write_u8((u8)u.l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
// dumps the raw value of the given field
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
void DumperSupport::dump_field_value(DumpWriter* writer, char type, address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
    case JVM_SIGNATURE_CLASS :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
    case JVM_SIGNATURE_ARRAY : {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 202
diff changeset
   757
      oop o;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 202
diff changeset
   758
      if (UseCompressedOops) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 202
diff changeset
   759
        o = oopDesc::load_decode_heap_oop((narrowOop*)addr);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 202
diff changeset
   760
      } else {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 202
diff changeset
   761
        o = oopDesc::load_decode_heap_oop((oop*)addr);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 202
diff changeset
   762
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
33606
af4ec8a4635b 8139891: Prepare Unsafe for true encapsulation
chegar
parents: 33604
diff changeset
   764
      // reflection and Unsafe classes may have a reference to a
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   765
      // Klass* so filter it out.
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31974
diff changeset
   766
      assert(o->is_oop_or_null(), "Expected an oop or NULL at " PTR_FORMAT, p2i(o));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
      writer->write_objectID(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
    case JVM_SIGNATURE_BYTE     : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
      jbyte* b = (jbyte*)addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
      writer->write_u1((u1)*b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
    case JVM_SIGNATURE_CHAR     : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
      jchar* c = (jchar*)addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
      writer->write_u2((u2)*c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
    case JVM_SIGNATURE_SHORT : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
      jshort* s = (jshort*)addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
      writer->write_u2((u2)*s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
    case JVM_SIGNATURE_FLOAT : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
      jfloat* f = (jfloat*)addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
      dump_float(writer, *f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
    case JVM_SIGNATURE_DOUBLE : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
      jdouble* f = (jdouble*)addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
      dump_double(writer, *f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
    case JVM_SIGNATURE_INT : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
      jint* i = (jint*)addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
      writer->write_u4((u4)*i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
    case JVM_SIGNATURE_LONG     : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
      jlong* l = (jlong*)addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
      writer->write_u8((u8)*l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
    case JVM_SIGNATURE_BOOLEAN : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
      jboolean* b = (jboolean*)addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
      writer->write_u1((u1)*b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
    default : ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
// returns the size of the instance of the given class
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   815
u4 DumperSupport::instance_size(Klass* k) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
  HandleMark hm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
  instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   819
  u4 size = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  for (FieldStream fld(ikh, false, false); !fld.eos(); fld.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
    if (!fld.access_flags().is_static()) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   823
      Symbol* sig = fld.signature();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
      switch (sig->byte_at(0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
        case JVM_SIGNATURE_CLASS   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
        case JVM_SIGNATURE_ARRAY   : size += oopSize; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
        case JVM_SIGNATURE_BYTE    :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
        case JVM_SIGNATURE_BOOLEAN : size += 1; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
        case JVM_SIGNATURE_CHAR    :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
        case JVM_SIGNATURE_SHORT   : size += 2; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
        case JVM_SIGNATURE_INT     :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
        case JVM_SIGNATURE_FLOAT   : size += 4; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
        case JVM_SIGNATURE_LONG    :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
        case JVM_SIGNATURE_DOUBLE  : size += 8; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
        default : ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
  }
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
   844
  return size;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
// dumps static fields of the given class
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   848
void DumperSupport::dump_static_fields(DumpWriter* writer, Klass* k) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
  HandleMark hm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
  instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  // pass 1 - count the static fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  u2 field_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
  for (FieldStream fldc(ikh, true, true); !fldc.eos(); fldc.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
    if (fldc.access_flags().is_static()) field_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  writer->write_u2(field_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  // pass 2 - dump the field descriptors and raw values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
  for (FieldStream fld(ikh, true, true); !fld.eos(); fld.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
    if (fld.access_flags().is_static()) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   863
      Symbol* sig = fld.signature();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   865
      writer->write_symbolID(fld.name());   // name
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
      writer->write_u1(sig2tag(sig));       // type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
      // value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
      int offset = fld.offset();
8726
7bafcf0e5bfb 7029509: nightly failures after static fields in Class
never
parents: 8295
diff changeset
   870
      address addr = (address)ikh->java_mirror() + offset;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
      dump_field_value(writer, sig->byte_at(0), addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
// dump the raw values of the instance fields of the given object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
void DumperSupport::dump_instance_fields(DumpWriter* writer, oop o) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
  HandleMark hm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), o->klass());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  for (FieldStream fld(ikh, false, false); !fld.eos(); fld.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
    if (!fld.access_flags().is_static()) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   884
      Symbol* sig = fld.signature();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
      address addr = (address)o + fld.offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
      dump_field_value(writer, sig->byte_at(0), addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
// dumps the definition of the instance fields for a given class
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   893
void DumperSupport::dump_instance_field_descriptors(DumpWriter* writer, Klass* k) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  HandleMark hm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
  instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
  // pass 1 - count the instance fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
  u2 field_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
  for (FieldStream fldc(ikh, true, true); !fldc.eos(); fldc.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
    if (!fldc.access_flags().is_static()) field_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
  writer->write_u2(field_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
  // pass 2 - dump the field descriptors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
  for (FieldStream fld(ikh, true, true); !fld.eos(); fld.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
    if (!fld.access_flags().is_static()) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   908
      Symbol* sig = fld.signature();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
   910
      writer->write_symbolID(fld.name());                   // name
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
      writer->write_u1(sig2tag(sig));       // type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
// creates HPROF_GC_INSTANCE_DUMP record for the given object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
void DumperSupport::dump_instance(DumpWriter* writer, oop o) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   918
  Klass* k = o->klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  writer->write_u1(HPROF_GC_INSTANCE_DUMP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
  writer->write_objectID(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  writer->write_u4(STACK_TRACE_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  // class ID
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   925
  writer->write_classID(k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
  // number of bytes that follow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
  writer->write_u4(instance_size(k) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
  // field values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
  dump_instance_fields(writer, o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
// creates HPROF_GC_CLASS_DUMP record for the given class and each of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
// its array classes
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   936
void DumperSupport::dump_class_and_array_classes(DumpWriter* writer, Klass* k) {
33602
16053580a684 8139163: InstanceKlass::cast passes through NULL
coleenp
parents: 33105
diff changeset
   937
  InstanceKlass* ik = InstanceKlass::cast(k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
33778
790c99403d3c 8134030: test/serviceability/dcmd/gc/HeapDumpTest fails to verify the dump
aeriksso
parents: 33612
diff changeset
   939
  // We can safepoint and do a heap dump at a point where we have a Klass,
790c99403d3c 8134030: test/serviceability/dcmd/gc/HeapDumpTest fails to verify the dump
aeriksso
parents: 33612
diff changeset
   940
  // but no java mirror class has been setup for it. So we need to check
790c99403d3c 8134030: test/serviceability/dcmd/gc/HeapDumpTest fails to verify the dump
aeriksso
parents: 33612
diff changeset
   941
  // that the class is at least loaded, to avoid crash from a null mirror.
790c99403d3c 8134030: test/serviceability/dcmd/gc/HeapDumpTest fails to verify the dump
aeriksso
parents: 33612
diff changeset
   942
  if (!ik->is_loaded()) {
31974
869b4f9cbb40 8131600: heapdump/JMapHeap EXCEPTION_ACCESS_VIOLATION
brutisso
parents: 30764
diff changeset
   943
    return;
869b4f9cbb40 8131600: heapdump/JMapHeap EXCEPTION_ACCESS_VIOLATION
brutisso
parents: 30764
diff changeset
   944
  }
869b4f9cbb40 8131600: heapdump/JMapHeap EXCEPTION_ACCESS_VIOLATION
brutisso
parents: 30764
diff changeset
   945
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
  writer->write_u1(HPROF_GC_CLASS_DUMP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
  // class ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
  writer->write_classID(ik);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
  writer->write_u4(STACK_TRACE_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
  // super class ID
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   953
  Klass* java_super = ik->java_super();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
  if (java_super == NULL) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   955
    writer->write_objectID(oop(NULL));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
  } else {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   957
    writer->write_classID(java_super);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
  writer->write_objectID(ik->class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
  writer->write_objectID(ik->signers());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
  writer->write_objectID(ik->protection_domain());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
  // reserved
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   965
  writer->write_objectID(oop(NULL));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   966
  writer->write_objectID(oop(NULL));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  // instance size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
  writer->write_u4(DumperSupport::instance_size(k));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
  // size of constant pool - ignored by HAT 1.1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
  writer->write_u2(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
  // number of static fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
  dump_static_fields(writer, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
  // description of instance fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
  dump_instance_field_descriptors(writer, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
  // array classes
33602
16053580a684 8139163: InstanceKlass::cast passes through NULL
coleenp
parents: 33105
diff changeset
   981
  k = k->array_klass_or_null();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  while (k != NULL) {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   983
    Klass* klass = k;
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   984
    assert(klass->is_objArray_klass(), "not an ObjArrayKlass");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
    writer->write_u1(HPROF_GC_CLASS_DUMP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
    writer->write_classID(klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
    writer->write_u4(STACK_TRACE_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
    // super class of array classes is java.lang.Object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
    java_super = klass->java_super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
    assert(java_super != NULL, "checking");
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   993
    writer->write_classID(java_super);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
    writer->write_objectID(ik->class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
    writer->write_objectID(ik->signers());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
    writer->write_objectID(ik->protection_domain());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   999
    writer->write_objectID(oop(NULL));    // reserved
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1000
    writer->write_objectID(oop(NULL));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
    writer->write_u4(0);             // instance size
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
    writer->write_u2(0);             // constant pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
    writer->write_u2(0);             // static fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
    writer->write_u2(0);             // instance fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
    // get the array class for the next rank
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
    k = klass->array_klass_or_null();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
// creates HPROF_GC_CLASS_DUMP record for a given primitive array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
// class (and each multi-dimensional array class too)
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1013
void DumperSupport::dump_basic_type_array_class(DumpWriter* writer, Klass* k) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
 // array classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
 while (k != NULL) {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1016
    Klass* klass = k;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
    writer->write_u1(HPROF_GC_CLASS_DUMP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
    writer->write_classID(klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
    writer->write_u4(STACK_TRACE_ID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
    // super class of array classes is java.lang.Object
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1023
    Klass* java_super = klass->java_super();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
    assert(java_super != NULL, "checking");
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1025
    writer->write_classID(java_super);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1027
    writer->write_objectID(oop(NULL));    // loader
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1028
    writer->write_objectID(oop(NULL));    // signers
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1029
    writer->write_objectID(oop(NULL));    // protection domain
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1031
    writer->write_objectID(oop(NULL));    // reserved
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1032
    writer->write_objectID(oop(NULL));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
    writer->write_u4(0);             // instance size
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
    writer->write_u2(0);             // constant pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
    writer->write_u2(0);             // static fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
    writer->write_u2(0);             // instance fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
    // get the array class for the next rank
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
    k = klass->array_klass_or_null();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1043
// Hprof uses an u4 as record length field,
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1044
// which means we need to truncate arrays that are too long.
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1045
int DumperSupport::calculate_array_max_length(DumpWriter* writer, arrayOop array, short header_size) {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1046
  BasicType type = ArrayKlass::cast(array->klass())->element_type();
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1047
  assert(type >= T_BOOLEAN && type <= T_OBJECT, "invalid array element type");
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1048
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1049
  int length = array->length();
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1050
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1051
  int type_size;
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1052
  if (type == T_OBJECT) {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1053
    type_size = sizeof(address);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1054
  } else {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1055
    type_size = type2aelembytes(type);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1056
  }
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1057
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1058
  size_t length_in_bytes = (size_t)length * type_size;
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1059
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1060
  // Create a new record if the current record is non-empty and the array can't fit.
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1061
  julong current_record_length = writer->current_record_length();
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1062
  if (current_record_length > 0 &&
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1063
      (current_record_length + header_size + length_in_bytes) > max_juint) {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1064
    write_current_dump_record_length(writer);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1065
    write_dump_header(writer);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1066
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1067
    // We now have an empty record.
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1068
    current_record_length = 0;
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1069
  }
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1070
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1071
  // Calculate max bytes we can use.
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1072
  uint max_bytes = max_juint - (header_size + current_record_length);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1073
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1074
  // Array too long for the record?
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1075
  // Calculate max length and return it.
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1076
  if (length_in_bytes > max_bytes) {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1077
    length = max_bytes / type_size;
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1078
    length_in_bytes = (size_t)length * type_size;
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1079
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1080
    warning("cannot dump array of type %s[] with length %d; truncating to length %d",
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1081
            type2name_tab[type], array->length(), length);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1082
  }
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1083
  return length;
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1084
}
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1085
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
// creates HPROF_GC_OBJ_ARRAY_DUMP record for the given object array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
void DumperSupport::dump_object_array(DumpWriter* writer, objArrayOop array) {
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1088
  // sizeof(u1) + 2 * sizeof(u4) + sizeof(objectID) + sizeof(classID)
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1089
  short header_size = 1 + 2 * 4 + 2 * sizeof(address);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1090
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1091
  int length = calculate_array_max_length(writer, array, header_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
  writer->write_u1(HPROF_GC_OBJ_ARRAY_DUMP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
  writer->write_objectID(array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
  writer->write_u4(STACK_TRACE_ID);
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1096
  writer->write_u4(length);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
  // array class ID
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1099
  writer->write_classID(array->klass());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
  // [id]* elements
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1102
  for (int index = 0; index < length; index++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
    oop o = array->obj_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
    writer->write_objectID(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1108
#define WRITE_ARRAY(Array, Type, Size, Length) \
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1109
  for (int i = 0; i < Length; i++) { writer->write_##Size((Size)Array->Type##_at(i)); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
// creates HPROF_GC_PRIM_ARRAY_DUMP record for the given type array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
void DumperSupport::dump_prim_array(DumpWriter* writer, typeArrayOop array) {
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13728
diff changeset
  1113
  BasicType type = TypeArrayKlass::cast(array->klass())->element_type();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1115
  // 2 * sizeof(u1) + 2 * sizeof(u4) + sizeof(objectID)
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1116
  short header_size = 2 * 1 + 2 * 4 + sizeof(address);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1117
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1118
  int length = calculate_array_max_length(writer, array, header_size);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1119
  int type_size = type2aelembytes(type);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1120
  u4 length_in_bytes = (u4)length * type_size;
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1121
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
  writer->write_u1(HPROF_GC_PRIM_ARRAY_DUMP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
  writer->write_objectID(array);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
  writer->write_u4(STACK_TRACE_ID);
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1125
  writer->write_u4(length);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
  writer->write_u1(type2tag(type));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
  // nothing to copy
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1129
  if (length == 0) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
  // If the byte ordering is big endian then we can copy most types directly
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
    case T_INT : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
      if (Bytes::is_Java_byte_ordering_different()) {
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1138
        WRITE_ARRAY(array, int, u4, length);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
        writer->write_raw((void*)(array->int_at_addr(0)), length_in_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
    case T_BYTE : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
      writer->write_raw((void*)(array->byte_at_addr(0)), length_in_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
    case T_CHAR : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
      if (Bytes::is_Java_byte_ordering_different()) {
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1150
        WRITE_ARRAY(array, char, u2, length);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
        writer->write_raw((void*)(array->char_at_addr(0)), length_in_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
    case T_SHORT : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
      if (Bytes::is_Java_byte_ordering_different()) {
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1158
        WRITE_ARRAY(array, short, u2, length);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
        writer->write_raw((void*)(array->short_at_addr(0)), length_in_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
    case T_BOOLEAN : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
      if (Bytes::is_Java_byte_ordering_different()) {
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1166
        WRITE_ARRAY(array, bool, u1, length);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
        writer->write_raw((void*)(array->bool_at_addr(0)), length_in_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
    case T_LONG : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
      if (Bytes::is_Java_byte_ordering_different()) {
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1174
        WRITE_ARRAY(array, long, u8, length);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
        writer->write_raw((void*)(array->long_at_addr(0)), length_in_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
    // handle float/doubles in a special value to ensure than NaNs are
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
    // written correctly. TO DO: Check if we can avoid this on processors that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
    // use IEEE 754.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
    case T_FLOAT : {
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1186
      for (int i = 0; i < length; i++) {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1187
        dump_float(writer, array->float_at(i));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
    case T_DOUBLE : {
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1192
      for (int i = 0; i < length; i++) {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1193
        dump_double(writer, array->double_at(i));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
    default : ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1201
// create a HPROF_FRAME record of the given Method* and bci
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1202
void DumperSupport::dump_stack_frame(DumpWriter* writer,
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1203
                                     int frame_serial_num,
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1204
                                     int class_serial_num,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1205
                                     Method* m,
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1206
                                     int bci) {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1207
  int line_number;
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1208
  if (m->is_native()) {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1209
    line_number = -3;  // native frame
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1210
  } else {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1211
    line_number = m->line_number_from_bci(bci);
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1212
  }
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1213
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1214
  write_header(writer, HPROF_FRAME, 4*oopSize + 2*sizeof(u4));
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1215
  writer->write_id(frame_serial_num);               // frame serial number
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
  1216
  writer->write_symbolID(m->name());                // method's name
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
  1217
  writer->write_symbolID(m->signature());           // method's signature
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1218
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
  1219
  assert(m->method_holder()->is_instance_klass(), "not InstanceKlass");
14391
df0a1573d5bd 8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents: 13952
diff changeset
  1220
  writer->write_symbolID(m->method_holder()->source_file_name());  // source file name
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1221
  writer->write_u4(class_serial_num);               // class serial number
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1222
  writer->write_u4((u4) line_number);               // line number
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1223
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
  1225
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
// Support class used to generate HPROF_UTF8 records from the entries in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
// SymbolTable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
  1229
class SymbolTableDumper : public SymbolClosure {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
  DumpWriter* _writer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
  DumpWriter* writer() const                { return _writer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
  SymbolTableDumper(DumpWriter* writer)     { _writer = writer; }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
  1235
  void do_symbol(Symbol** p);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
  1238
void SymbolTableDumper::do_symbol(Symbol** p) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
  ResourceMark rm;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
  1240
  Symbol* sym = load_symbol(p);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
  int len = sym->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
  if (len > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
    char* s = sym->as_utf8();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
    DumperSupport::write_header(writer(), HPROF_UTF8, oopSize + len);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
  1245
    writer()->write_symbolID(sym);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
    writer()->write_raw(s, len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
// Support class used to generate HPROF_GC_ROOT_JNI_LOCAL records
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
class JNILocalsDumper : public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
  DumpWriter* _writer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
  u4 _thread_serial_num;
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1256
  int _frame_num;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
  DumpWriter* writer() const                { return _writer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
  JNILocalsDumper(DumpWriter* writer, u4 thread_serial_num) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
    _writer = writer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
    _thread_serial_num = thread_serial_num;
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1262
    _frame_num = -1;  // default - empty stack
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
  }
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1264
  void set_frame_number(int n) { _frame_num = n; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
  void do_oop(oop* obj_p);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 202
diff changeset
  1266
  void do_oop(narrowOop* obj_p) { ShouldNotReachHere(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
void JNILocalsDumper::do_oop(oop* obj_p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
  // ignore null or deleted handles
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
  oop o = *obj_p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
  if (o != NULL && o != JNIHandles::deleted_handle()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
    writer()->write_u1(HPROF_GC_ROOT_JNI_LOCAL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
    writer()->write_objectID(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
    writer()->write_u4(_thread_serial_num);
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1277
    writer()->write_u4((u4)_frame_num);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
// Support class used to generate HPROF_GC_ROOT_JNI_GLOBAL records
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
class JNIGlobalsDumper : public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
  DumpWriter* _writer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
  DumpWriter* writer() const                { return _writer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
  JNIGlobalsDumper(DumpWriter* writer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
    _writer = writer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
  void do_oop(oop* obj_p);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 202
diff changeset
  1294
  void do_oop(narrowOop* obj_p) { ShouldNotReachHere(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
void JNIGlobalsDumper::do_oop(oop* obj_p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
  oop o = *obj_p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
  // ignore these
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
  if (o == NULL || o == JNIHandles::deleted_handle()) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
  // we ignore global ref to symbols and other internal objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
  if (o->is_instance() || o->is_objArray() || o->is_typeArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
    writer()->write_u1(HPROF_GC_ROOT_JNI_GLOBAL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
    writer()->write_objectID(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
    writer()->write_objectID((oopDesc*)obj_p);      // global ref ID
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
// Support class used to generate HPROF_GC_ROOT_MONITOR_USED records
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
class MonitorUsedDumper : public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
  DumpWriter* _writer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
  DumpWriter* writer() const                { return _writer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
  MonitorUsedDumper(DumpWriter* writer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
    _writer = writer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
  void do_oop(oop* obj_p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
    writer()->write_u1(HPROF_GC_ROOT_MONITOR_USED);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
    writer()->write_objectID(*obj_p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
  }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 202
diff changeset
  1326
  void do_oop(narrowOop* obj_p) { ShouldNotReachHere(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
// Support class used to generate HPROF_GC_ROOT_STICKY_CLASS records
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1332
class StickyClassDumper : public KlassClosure {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
  DumpWriter* _writer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
  DumpWriter* writer() const                { return _writer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
  StickyClassDumper(DumpWriter* writer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
    _writer = writer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1340
  void do_klass(Klass* k) {
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
  1341
    if (k->is_instance_klass()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1342
      InstanceKlass* ik = InstanceKlass::cast(k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
        writer()->write_u1(HPROF_GC_ROOT_STICKY_CLASS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
        writer()->write_classID(ik);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1347
};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
class VM_HeapDumper;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
// Support class using when iterating over the heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
class HeapObjectDumper : public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
  VM_HeapDumper* _dumper;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
  DumpWriter* _writer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
  VM_HeapDumper* dumper()               { return _dumper; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
  DumpWriter* writer()                  { return _writer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
  // used to indicate that a record has been writen
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
  void mark_end_of_record();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
  HeapObjectDumper(VM_HeapDumper* dumper, DumpWriter* writer) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
    _dumper = dumper;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
    _writer = writer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
  // called for each object in the heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
  void do_object(oop o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
void HeapObjectDumper::do_object(oop o) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
  // hide the sentinel for deleted handles
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
  if (o == JNIHandles::deleted_handle()) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
  // skip classes as these emitted as HPROF_GC_CLASS_DUMP records
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4101
diff changeset
  1380
  if (o->klass() == SystemDictionary::Class_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
    if (!java_lang_Class::is_primitive(o)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
  if (o->is_instance()) {
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
  1387
    // create a HPROF_GC_INSTANCE record for each object
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
    DumperSupport::dump_instance(writer(), o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
    mark_end_of_record();
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
  1390
  } else if (o->is_objArray()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
    // create a HPROF_GC_OBJ_ARRAY_DUMP record for each object array
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
  1392
    DumperSupport::dump_object_array(writer(), objArrayOop(o));
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
  1393
    mark_end_of_record();
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
  1394
  } else if (o->is_typeArray()) {
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
  1395
    // create a HPROF_GC_PRIM_ARRAY_DUMP record for each type array
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
  1396
    DumperSupport::dump_prim_array(writer(), typeArrayOop(o));
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
  1397
    mark_end_of_record();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
// The VM operation that performs the heap dump
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
class VM_HeapDumper : public VM_GC_Operation {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
 private:
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1404
  static VM_HeapDumper* _global_dumper;
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1405
  static DumpWriter*    _global_writer;
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1406
  DumpWriter*           _local_writer;
6445
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1407
  JavaThread*           _oome_thread;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1408
  Method*               _oome_constructor;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
  bool _gc_before_heap_dump;
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1410
  GrowableArray<Klass*>* _klass_map;
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1411
  ThreadStackTrace** _stack_traces;
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1412
  int _num_threads;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1414
  // accessors and setters
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1415
  static VM_HeapDumper* dumper()         {  assert(_global_dumper != NULL, "Error"); return _global_dumper; }
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1416
  static DumpWriter* writer()            {  assert(_global_writer != NULL, "Error"); return _global_writer; }
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1417
  void set_global_dumper() {
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1418
    assert(_global_dumper == NULL, "Error");
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1419
    _global_dumper = this;
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1420
  }
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1421
  void set_global_writer() {
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1422
    assert(_global_writer == NULL, "Error");
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1423
    _global_writer = _local_writer;
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1424
  }
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1425
  void clear_global_dumper() { _global_dumper = NULL; }
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1426
  void clear_global_writer() { _global_writer = NULL; }
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1427
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
  bool skip_operation() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
  // writes a HPROF_LOAD_CLASS record
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1431
  static void do_load_class(Klass* k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
  // writes a HPROF_GC_CLASS_DUMP record for the given class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
  // (and each array class too)
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1435
  static void do_class_dump(Klass* k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
  // writes a HPROF_GC_CLASS_DUMP records for a given basic type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
  // array (and each multi-dimensional array too)
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1439
  static void do_basic_type_array_class_dump(Klass* k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
  // HPROF_GC_ROOT_THREAD_OBJ records
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1442
  int do_thread(JavaThread* thread, u4 thread_serial_num);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
  void do_threads();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1445
  void add_class_serial_number(Klass* k, int serial_num) {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1446
    _klass_map->at_put_grow(serial_num, k);
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1447
  }
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1448
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1449
  // HPROF_TRACE and HPROF_FRAME records
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1450
  void dump_stack_traces();
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1451
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
 public:
6445
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1453
  VM_HeapDumper(DumpWriter* writer, bool gc_before_heap_dump, bool oome) :
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
    VM_GC_Operation(0 /* total collections,      dummy, ignored */,
8295
a2b2a8a3aaee 7015169: GC Cause not always set
brutisso
parents: 8076
diff changeset
  1455
                    GCCause::_heap_dump /* GC Cause */,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
                    0 /* total full collections, dummy, ignored */,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
                    gc_before_heap_dump) {
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1458
    _local_writer = writer;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
    _gc_before_heap_dump = gc_before_heap_dump;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11000
diff changeset
  1460
    _klass_map = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<Klass*>(INITIAL_CLASS_COUNT, true);
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1461
    _stack_traces = NULL;
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1462
    _num_threads = 0;
6445
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1463
    if (oome) {
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1464
      assert(!Thread::current()->is_VM_thread(), "Dump from OutOfMemoryError cannot be called by the VMThread");
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1465
      // get OutOfMemoryError zero-parameter constructor
33602
16053580a684 8139163: InstanceKlass::cast passes through NULL
coleenp
parents: 33105
diff changeset
  1466
      InstanceKlass* oome_ik = SystemDictionary::OutOfMemoryError_klass();
6445
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1467
      _oome_constructor = oome_ik->find_method(vmSymbols::object_initializer_name(),
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1468
                                                          vmSymbols::void_method_signature());
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1469
      // get thread throwing OOME when generating the heap dump at OOME
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1470
      _oome_thread = JavaThread::current();
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1471
    } else {
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1472
      _oome_thread = NULL;
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1473
      _oome_constructor = NULL;
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1474
    }
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1475
  }
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1476
  ~VM_HeapDumper() {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1477
    if (_stack_traces != NULL) {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1478
      for (int i=0; i < _num_threads; i++) {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1479
        delete _stack_traces[i];
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1480
      }
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 26831
diff changeset
  1481
      FREE_C_HEAP_ARRAY(ThreadStackTrace*, _stack_traces);
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1482
    }
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1483
    delete _klass_map;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
  VMOp_Type type() const { return VMOp_HeapDumper; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
  // used to mark sub-record boundary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
  void check_segment_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
  void doit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1492
VM_HeapDumper* VM_HeapDumper::_global_dumper = NULL;
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1493
DumpWriter*    VM_HeapDumper::_global_writer = NULL;
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1494
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
bool VM_HeapDumper::skip_operation() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1499
 // writes a HPROF_HEAP_DUMP_SEGMENT record
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1500
void DumperSupport::write_dump_header(DumpWriter* writer) {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1501
  if (writer->is_open()) {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1502
    writer->write_u1(HPROF_HEAP_DUMP_SEGMENT);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1503
    writer->write_u4(0); // current ticks
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
    // record the starting position for the dump (its length will be fixed up later)
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1506
    writer->set_dump_start(writer->current_offset());
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1507
    writer->write_u4(0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
// fixes up the length of the current dump record
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1512
void DumperSupport::write_current_dump_record_length(DumpWriter* writer) {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1513
  if (writer->is_open()) {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1514
    julong dump_end = writer->bytes_written() + writer->bytes_unwritten();
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1515
    julong dump_len = writer->current_record_length();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
    // record length must fit in a u4
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
  1518
    if (dump_len > max_juint) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
      warning("record is too large");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
    // seek to the dump start and fix-up the length
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1523
    assert(writer->dump_start() >= 0, "no dump start recorded");
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1524
    writer->seek_to_offset(writer->dump_start());
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1525
    writer->write_u4((u4)dump_len);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
    // adjust the total size written to keep the bytes written correct.
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1528
    writer->adjust_bytes_written(-((jlong) sizeof(u4)));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
    // seek to dump end so we can continue
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1531
    writer->seek_to_offset(dump_end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
    // no current dump record
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1534
    writer->set_dump_start((jlong)-1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
// used on a sub-record boundary to check if we need to start a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
// new segment.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
void VM_HeapDumper::check_segment_length() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
  if (writer()->is_open()) {
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1542
    julong dump_len = writer()->current_record_length();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1544
    if (dump_len > 2UL*G) {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1545
      DumperSupport::write_current_dump_record_length(writer());
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1546
      DumperSupport::write_dump_header(writer());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1551
// fixes up the current dump record and writes HPROF_HEAP_DUMP_END record
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1552
void DumperSupport::end_of_dump(DumpWriter* writer) {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1553
  if (writer->is_open()) {
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1554
    write_current_dump_record_length(writer);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1556
    writer->write_u1(HPROF_HEAP_DUMP_END);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1557
    writer->write_u4(0);
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1558
    writer->write_u4(0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
// marks sub-record boundary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
void HeapObjectDumper::mark_end_of_record() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
  dumper()->check_segment_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
// writes a HPROF_LOAD_CLASS record for the class (and each of its
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
// array classes)
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1569
void VM_HeapDumper::do_load_class(Klass* k) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
  static u4 class_serial_num = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
  // len of HPROF_LOAD_CLASS record
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
  u4 remaining = 2*oopSize + 2*sizeof(u4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
  // write a HPROF_LOAD_CLASS for the class and each array class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
  do {
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1577
    DumperSupport::write_header(writer(), HPROF_LOAD_CLASS, remaining);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
    // class serial number is just a number
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1580
    writer()->write_u4(++class_serial_num);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
    // class ID
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1583
    Klass* klass = k;
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1584
    writer()->write_classID(klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1586
    // add the Klass* and class serial number pair
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1587
    dumper()->add_class_serial_number(klass, class_serial_num);
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1588
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1589
    writer()->write_u4(STACK_TRACE_ID);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
    // class name ID
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
  1592
    Symbol* name = klass->name();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
  1593
    writer()->write_symbolID(name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
    // write a LOAD_CLASS record for the array type (if it exists)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
    k = klass->array_klass_or_null();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
  } while (k != NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
// writes a HPROF_GC_CLASS_DUMP record for the given class
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1601
void VM_HeapDumper::do_class_dump(Klass* k) {
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
  1602
  if (k->is_instance_klass()) {
20675
ae7f1f0b5e11 8024425: VM_HeapDumper doesn't put anonymous classes in the heap dump
sla
parents: 20282
diff changeset
  1603
    DumperSupport::dump_class_and_array_classes(writer(), k);
ae7f1f0b5e11 8024425: VM_HeapDumper doesn't put anonymous classes in the heap dump
sla
parents: 20282
diff changeset
  1604
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
// writes a HPROF_GC_CLASS_DUMP records for a given basic type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
// array (and each multi-dimensional array too)
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1609
void VM_HeapDumper::do_basic_type_array_class_dump(Klass* k) {
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1610
  DumperSupport::dump_basic_type_array_class(writer(), k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
// Walk the stack of the given thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
// Dumps a HPROF_GC_ROOT_JAVA_FRAME record for each local
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
// Dumps a HPROF_GC_ROOT_JNI_LOCAL record for each JNI local
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1616
//
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1617
// It returns the number of Java frames in this thread stack
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1618
int VM_HeapDumper::do_thread(JavaThread* java_thread, u4 thread_serial_num) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
  JNILocalsDumper blk(writer(), thread_serial_num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
  oop threadObj = java_thread->threadObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
  assert(threadObj != NULL, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1624
  int stack_depth = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
  if (java_thread->has_last_Java_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
    // vframes are resource allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
    Thread* current_thread = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
    ResourceMark rm(current_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
    HandleMark hm(current_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
    RegisterMap reg_map(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
    frame f = java_thread->last_frame();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
    vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1635
    frame* last_entry_frame = NULL;
6445
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1636
    int extra_frames = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
6445
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1638
    if (java_thread == _oome_thread && _oome_constructor != NULL) {
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1639
      extra_frames++;
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1640
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
    while (vf != NULL) {
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1642
      blk.set_frame_number(stack_depth);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
      if (vf->is_java_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
        // java frame (interpreted, compiled, ...)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
        javaVFrame *jvf = javaVFrame::cast(vf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
        if (!(jvf->method()->is_native())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
          StackValueCollection* locals = jvf->locals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
          for (int slot=0; slot<locals->size(); slot++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
            if (locals->at(slot)->type() == T_OBJECT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
              oop o = locals->obj_at(slot)();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
              if (o != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
                writer()->write_u1(HPROF_GC_ROOT_JAVA_FRAME);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
                writer()->write_objectID(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
                writer()->write_u4(thread_serial_num);
6445
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1657
                writer()->write_u4((u4) (stack_depth + extra_frames));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
          }
22895
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 20675
diff changeset
  1661
          StackValueCollection *exprs = jvf->expressions();
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 20675
diff changeset
  1662
          for(int index = 0; index < exprs->size(); index++) {
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 20675
diff changeset
  1663
            if (exprs->at(index)->type() == T_OBJECT) {
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 20675
diff changeset
  1664
               oop o = exprs->obj_at(index)();
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 20675
diff changeset
  1665
               if (o != NULL) {
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 20675
diff changeset
  1666
                 writer()->write_u1(HPROF_GC_ROOT_JAVA_FRAME);
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 20675
diff changeset
  1667
                 writer()->write_objectID(o);
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 20675
diff changeset
  1668
                 writer()->write_u4(thread_serial_num);
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 20675
diff changeset
  1669
                 writer()->write_u4((u4) (stack_depth + extra_frames));
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 20675
diff changeset
  1670
               }
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 20675
diff changeset
  1671
             }
52fbddf39901 8034867: Object references from expression stack are not visible as roots via jvmti FollowReferences and HeapDump
sspitsyn
parents: 20675
diff changeset
  1672
          }
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1673
        } else {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1674
          // native frame
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1675
          if (stack_depth == 0) {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1676
            // JNI locals for the top frame.
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1677
            java_thread->active_handles()->oops_do(&blk);
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1678
          } else {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1679
            if (last_entry_frame != NULL) {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1680
              // JNI locals for the entry frame
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1681
              assert(last_entry_frame->is_entry_frame(), "checking");
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1682
              last_entry_frame->entry_frame_call_wrapper()->handles()->oops_do(&blk);
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1683
            }
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1684
          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
        }
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1686
        // increment only for Java frames
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1687
        stack_depth++;
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1688
        last_entry_frame = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1690
      } else {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
        // externalVFrame - if it's an entry frame then report any JNI locals
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1692
        // as roots when we find the corresponding native javaVFrame
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
        frame* fr = vf->frame_pointer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
        assert(fr != NULL, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
        if (fr->is_entry_frame()) {
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1696
          last_entry_frame = fr;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
      vf = vf->sender();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
    }
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1701
  } else {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1702
    // no last java frame but there may be JNI locals
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1703
    java_thread->active_handles()->oops_do(&blk);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
  }
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1705
  return stack_depth;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
// write a HPROF_GC_ROOT_THREAD_OBJ record for each java thread. Then walk
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
// the stack so that locals and JNI locals are dumped.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
void VM_HeapDumper::do_threads() {
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1712
  for (int i=0; i < _num_threads; i++) {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1713
    JavaThread* thread = _stack_traces[i]->thread();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
    oop threadObj = thread->threadObj();
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1715
    u4 thread_serial_num = i+1;
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1716
    u4 stack_serial_num = thread_serial_num + STACK_TRACE_ID;
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1717
    writer()->write_u1(HPROF_GC_ROOT_THREAD_OBJ);
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1718
    writer()->write_objectID(threadObj);
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1719
    writer()->write_u4(thread_serial_num);  // thread number
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1720
    writer()->write_u4(stack_serial_num);   // stack trace serial number
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1721
    int num_frames = do_thread(thread, thread_serial_num);
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1722
    assert(num_frames == _stack_traces[i]->get_stack_depth(),
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1723
           "total number of Java frames not matched");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
// The VM operation that dumps the heap. The dump consists of the following
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
// records:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
//  HPROF_HEADER
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
//  [HPROF_UTF8]*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
//  [HPROF_LOAD_CLASS]*
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1734
//  [[HPROF_FRAME]*|HPROF_TRACE]*
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
//  [HPROF_GC_CLASS_DUMP]*
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1736
//  [HPROF_HEAP_DUMP_SEGMENT]*
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1737
//  HPROF_HEAP_DUMP_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
//
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1739
// The HPROF_TRACE records represent the stack traces where the heap dump
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1740
// is generated and a "dummy trace" record which does not include
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1741
// any frames. The dummy trace record is used to be referenced as the
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1742
// unknown object alloc site.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
//
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1744
// Each HPROF_HEAP_DUMP_SEGMENT record has a length followed by sub-records.
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1745
// To allow the heap dump be generated in a single pass we remember the position
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1746
// of the dump length and fix it up after all sub-records have been written.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
// To generate the sub-records we iterate over the heap, writing
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
// HPROF_GC_INSTANCE_DUMP, HPROF_GC_OBJ_ARRAY_DUMP, and HPROF_GC_PRIM_ARRAY_DUMP
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
// records as we go. Once that is done we write records for some of the GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
// roots.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
void VM_HeapDumper::doit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
  HandleMark hm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
  CollectedHeap* ch = Universe::heap();
11000
e7c4440c05e2 7110428: Crash during HeapDump operation
poonam
parents: 9630
diff changeset
  1756
e7c4440c05e2 7110428: Crash during HeapDump operation
poonam
parents: 9630
diff changeset
  1757
  ch->ensure_parsability(false); // must happen, even if collection does
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 33794
diff changeset
  1758
                                 // not happen (e.g. due to GCLocker)
11000
e7c4440c05e2 7110428: Crash during HeapDump operation
poonam
parents: 9630
diff changeset
  1759
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
  if (_gc_before_heap_dump) {
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 33794
diff changeset
  1761
    if (GCLocker::is_active()) {
11000
e7c4440c05e2 7110428: Crash during HeapDump operation
poonam
parents: 9630
diff changeset
  1762
      warning("GC locker is held; pre-heapdump GC was skipped");
e7c4440c05e2 7110428: Crash during HeapDump operation
poonam
parents: 9630
diff changeset
  1763
    } else {
e7c4440c05e2 7110428: Crash during HeapDump operation
poonam
parents: 9630
diff changeset
  1764
      ch->collect_as_vm_thread(GCCause::_heap_dump);
e7c4440c05e2 7110428: Crash during HeapDump operation
poonam
parents: 9630
diff changeset
  1765
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1768
  // At this point we should be the only dumper active, so
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1769
  // the following should be safe.
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1770
  set_global_dumper();
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1771
  set_global_writer();
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1772
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1773
  // Write the file header - we always use 1.0.2
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
  1774
  size_t used = ch->used();
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1775
  const char* header = "JAVA PROFILE 1.0.2";
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1776
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
  // header is few bytes long - no chance to overflow int
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
  writer()->write_raw((void*)header, (int)strlen(header));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
  writer()->write_u1(0); // terminator
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
  writer()->write_u4(oopSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
  writer()->write_u8(os::javaTimeMillis());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
  // HPROF_UTF8 records
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
  SymbolTableDumper sym_dumper(writer());
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7914
diff changeset
  1785
  SymbolTable::symbols_do(&sym_dumper);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
  // write HPROF_LOAD_CLASS records
20675
ae7f1f0b5e11 8024425: VM_HeapDumper doesn't put anonymous classes in the heap dump
sla
parents: 20282
diff changeset
  1788
  ClassLoaderDataGraph::classes_do(&do_load_class);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
  Universe::basic_type_classes_do(&do_load_class);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1791
  // write HPROF_FRAME and HPROF_TRACE records
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1792
  // this must be called after _klass_map is built when iterating the classes above.
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1793
  dump_stack_traces();
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1794
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1795
  // write HPROF_HEAP_DUMP_SEGMENT
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1796
  DumperSupport::write_dump_header(writer());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
  // Writes HPROF_GC_CLASS_DUMP records
20675
ae7f1f0b5e11 8024425: VM_HeapDumper doesn't put anonymous classes in the heap dump
sla
parents: 20282
diff changeset
  1799
  ClassLoaderDataGraph::classes_do(&do_class_dump);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
  Universe::basic_type_classes_do(&do_basic_type_array_class_dump);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
  check_segment_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
  // writes HPROF_GC_INSTANCE_DUMP records.
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1804
  // After each sub-record is written check_segment_length will be invoked
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1805
  // to check if the current segment exceeds a threshold. If so, a new
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1806
  // segment is started.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
  // The HPROF_GC_CLASS_DUMP and HPROF_GC_INSTANCE_DUMP are the vast bulk
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
  // of the heap dump.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
  HeapObjectDumper obj_dumper(this, writer());
1893
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 1428
diff changeset
  1810
  Universe::heap()->safe_object_iterate(&obj_dumper);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
  // HPROF_GC_ROOT_THREAD_OBJ + frames + jni locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
  do_threads();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
  check_segment_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
  // HPROF_GC_ROOT_MONITOR_USED
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
  MonitorUsedDumper mon_dumper(writer());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
  ObjectSynchronizer::oops_do(&mon_dumper);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
  check_segment_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
  // HPROF_GC_ROOT_JNI_GLOBAL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
  JNIGlobalsDumper jni_dumper(writer());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
  JNIHandles::oops_do(&jni_dumper);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
  check_segment_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
  // HPROF_GC_ROOT_STICKY_CLASS
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
  StickyClassDumper class_dumper(writer());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1828
  SystemDictionary::always_strong_classes_do(&class_dumper);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
36375
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1830
  // fixes up the length of the dump record and writes the HPROF_HEAP_DUMP_END record.
d96a3220c7bb 8144732: VM_HeapDumper hits assert with bad dump_len
aeriksso
parents: 35528
diff changeset
  1831
  DumperSupport::end_of_dump(writer());
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1832
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1833
  // Now we clear the global variables, so that a future dumper might run.
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1834
  clear_global_dumper();
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1835
  clear_global_writer();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1838
void VM_HeapDumper::dump_stack_traces() {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1839
  // write a HPROF_TRACE record without any frames to be referenced as object alloc sites
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1840
  DumperSupport::write_header(writer(), HPROF_TRACE, 3*sizeof(u4));
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1841
  writer()->write_u4((u4) STACK_TRACE_ID);
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1842
  writer()->write_u4(0);                    // thread number
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1843
  writer()->write_u4(0);                    // frame count
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1844
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11000
diff changeset
  1845
  _stack_traces = NEW_C_HEAP_ARRAY(ThreadStackTrace*, Threads::number_of_threads(), mtInternal);
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1846
  int frame_serial_num = 0;
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1847
  for (JavaThread* thread = Threads::first(); thread != NULL ; thread = thread->next()) {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1848
    oop threadObj = thread->threadObj();
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1849
    if (threadObj != NULL && !thread->is_exiting() && !thread->is_hidden_from_external_view()) {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1850
      // dump thread stack trace
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1851
      ThreadStackTrace* stack_trace = new ThreadStackTrace(thread, false);
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1852
      stack_trace->dump_stack_at_safepoint(-1);
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1853
      _stack_traces[_num_threads++] = stack_trace;
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1854
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1855
      // write HPROF_FRAME records for this thread's stack trace
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1856
      int depth = stack_trace->get_stack_depth();
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1857
      int thread_frame_start = frame_serial_num;
6445
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1858
      int extra_frames = 0;
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1859
      // write fake frame that makes it look like the thread, which caused OOME,
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1860
      // is in the OutOfMemoryError zero-parameter constructor
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1861
      if (thread == _oome_thread && _oome_constructor != NULL) {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1862
        int oome_serial_num = _klass_map->find(_oome_constructor->method_holder());
6445
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1863
        // the class serial number starts from 1
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1864
        assert(oome_serial_num > 0, "OutOfMemoryError class not found");
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1865
        DumperSupport::dump_stack_frame(writer(), ++frame_serial_num, oome_serial_num,
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1866
                                        _oome_constructor, 0);
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1867
        extra_frames++;
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1868
      }
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1869
      for (int j=0; j < depth; j++) {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1870
        StackFrameInfo* frame = stack_trace->stack_frame_at(j);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1871
        Method* m = frame->method();
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1872
        int class_serial_num = _klass_map->find(m->method_holder());
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1873
        // the class serial number starts from 1
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1874
        assert(class_serial_num > 0, "class not found");
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1875
        DumperSupport::dump_stack_frame(writer(), ++frame_serial_num, class_serial_num, m, frame->bci());
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1876
      }
6445
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1877
      depth += extra_frames;
1428
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1878
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1879
      // write HPROF_TRACE record for one thread
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1880
      DumperSupport::write_header(writer(), HPROF_TRACE, 3*sizeof(u4) + depth*oopSize);
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1881
      int stack_serial_num = _num_threads + STACK_TRACE_ID;
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1882
      writer()->write_u4(stack_serial_num);      // stack trace serial number
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1883
      writer()->write_u4((u4) _num_threads);     // thread serial number
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1884
      writer()->write_u4(depth);                 // frame count
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1885
      for (int j=1; j <= depth; j++) {
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1886
        writer()->write_id(thread_frame_start + j);
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1887
      }
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1888
    }
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1889
  }
147c6bcaa316 6306922: Dump dump created by +HeapDumpOnOutOfMemoryError should include stack traces for stack roots
mchung
parents: 1388
diff changeset
  1890
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
// dump the heap to given path.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
int HeapDumper::dump(const char* path) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
  assert(path != NULL && strlen(path) > 0, "path missing");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1896
  // print message in interactive case
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
  if (print_to_tty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
    tty->print_cr("Dumping heap to %s ...", path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
    timer()->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
  // create the dump writer. If the file can be opened then bail
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
  DumpWriter writer(path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
  if (!writer.is_open()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
    set_error(writer.error());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
    if (print_to_tty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
      tty->print_cr("Unable to create %s: %s", path,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
        (error() != NULL) ? error() : "reason unknown");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1912
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1913
  // generate the dump
6445
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1914
  VM_HeapDumper dumper(&writer, _gc_before_heap_dump, _oome);
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1915
  if (Thread::current()->is_VM_thread()) {
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1916
    assert(SafepointSynchronize::is_at_safepoint(), "Expected to be called at a safepoint");
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1917
    dumper.doit();
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1918
  } else {
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1919
    VMThread::execute(&dumper);
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1920
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1921
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1922
  // close dump file and record any error that the writer may have encountered
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1923
  writer.close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1924
  set_error(writer.error());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1925
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1926
  // print message in interactive case
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1927
  if (print_to_tty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1928
    timer()->stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1929
    if (error() == NULL) {
35528
f8a8d6664a19 8129419: heapDumper.cpp: assert(length_in_bytes > 0) failed: nothing to copy
aeriksso
parents: 35492
diff changeset
  1930
      tty->print_cr("Heap dump file created [" JULONG_FORMAT " bytes in %3.3f secs]",
33604
ad1cd9269bd4 8139116: Fixes for warning "format not a string literal"
goetz
parents: 33602
diff changeset
  1931
                    writer.bytes_written(), timer()->seconds());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1932
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1933
      tty->print_cr("Dump file is incomplete: %s", writer.error());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1934
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1935
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1936
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1937
  return (writer.error() == NULL) ? 0 : -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1938
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1939
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1940
// stop timer (if still active), and free any error string we might be holding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1941
HeapDumper::~HeapDumper() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1942
  if (timer()->is_active()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1943
    timer()->stop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1944
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1945
  set_error(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1946
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1947
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1948
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1949
// returns the error string (resource allocated), or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1950
char* HeapDumper::error_as_C_string() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1951
  if (error() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1952
    char* str = NEW_RESOURCE_ARRAY(char, strlen(error())+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1953
    strcpy(str, error());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1954
    return str;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1955
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1956
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1957
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1958
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1959
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1960
// set the error string
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1961
void HeapDumper::set_error(char* error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1962
  if (_error != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1963
    os::free(_error);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1964
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1965
  if (error == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1966
    _error = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1967
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1968
    _error = os::strdup(error);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1969
    assert(_error != NULL, "allocation failure");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1970
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1971
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1972
6445
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1973
// Called by out-of-memory error reporting by a single Java thread
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1974
// outside of a JVM safepoint
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1975
void HeapDumper::dump_heap_from_oome() {
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1976
  HeapDumper::dump_heap(true);
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1977
}
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1978
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1979
// Called by error reporting by a single Java thread outside of a JVM safepoint,
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1980
// or by heap dumping by the VM thread during a (GC) safepoint. Thus, these various
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1981
// callers are strictly serialized and guaranteed not to interfere below. For more
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1982
// general use, however, this method will need modification to prevent
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1983
// inteference when updating the static variables base_path and dump_file_seq below.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1984
void HeapDumper::dump_heap() {
6445
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1985
  HeapDumper::dump_heap(false);
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1986
}
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1987
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  1988
void HeapDumper::dump_heap(bool oome) {
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1989
  static char base_path[JVM_MAXPATHLEN] = {'\0'};
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  1990
  static uint dump_file_seq = 0;
7914
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  1991
  char* my_path;
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  1992
  const int max_digit_chars = 20;
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  1993
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  1994
  const char* dump_file_name = "java_pid";
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  1995
  const char* dump_file_ext  = ".hprof";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1996
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1997
  // The dump file defaults to java_pid<pid>.hprof in the current working
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1998
  // directory. HeapDumpPath=<file> can be used to specify an alternative
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1999
  // dump file name or a directory where dump file is created.
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2000
  if (dump_file_seq == 0) { // first time in, we initialize base_path
7914
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2001
    // Calculate potentially longest base path and check if we have enough
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2002
    // allocated statically.
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2003
    const size_t total_length =
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2004
                      (HeapDumpPath == NULL ? 0 : strlen(HeapDumpPath)) +
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2005
                      strlen(os::file_separator()) + max_digit_chars +
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2006
                      strlen(dump_file_name) + strlen(dump_file_ext) + 1;
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2007
    if (total_length > sizeof(base_path)) {
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2008
      warning("Cannot create heap dump file.  HeapDumpPath is too long.");
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2009
      return;
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2010
    }
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2011
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2012
    bool use_default_filename = true;
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2013
    if (HeapDumpPath == NULL || HeapDumpPath[0] == '\0') {
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2014
      // HeapDumpPath=<file> not specified
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2015
    } else {
33794
41ef3dc95179 8140482: Various minor code improvements (runtime)
goetz
parents: 33778
diff changeset
  2016
      strcpy(base_path, HeapDumpPath);
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2017
      // check if the path is a directory (must exist)
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2018
      DIR* dir = os::opendir(base_path);
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2019
      if (dir == NULL) {
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2020
        use_default_filename = false;
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2021
      } else {
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2022
        // HeapDumpPath specified a directory. We append a file separator
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2023
        // (if needed).
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2024
        os::closedir(dir);
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2025
        size_t fs_len = strlen(os::file_separator());
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2026
        if (strlen(base_path) >= fs_len) {
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2027
          char* end = base_path;
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2028
          end += (strlen(base_path) - fs_len);
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2029
          if (strcmp(end, os::file_separator()) != 0) {
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2030
            strcat(base_path, os::file_separator());
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2031
          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2032
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2033
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2034
    }
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2035
    // If HeapDumpPath wasn't a file name then we append the default name
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2036
    if (use_default_filename) {
7914
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2037
      const size_t dlen = strlen(base_path);  // if heap dump dir specified
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2038
      jio_snprintf(&base_path[dlen], sizeof(base_path)-dlen, "%s%d%s",
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2039
                   dump_file_name, os::current_process_id(), dump_file_ext);
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2040
    }
7914
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2041
    const size_t len = strlen(base_path) + 1;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11000
diff changeset
  2042
    my_path = (char*)os::malloc(len, mtInternal);
7914
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2043
    if (my_path == NULL) {
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2044
      warning("Cannot create heap dump file.  Out of system memory.");
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2045
      return;
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2046
    }
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2047
    strncpy(my_path, base_path, len);
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2048
  } else {
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2049
    // Append a sequence number id for dumps following the first
7914
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2050
    const size_t len = strlen(base_path) + max_digit_chars + 2; // for '.' and \0
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11000
diff changeset
  2051
    my_path = (char*)os::malloc(len, mtInternal);
7914
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2052
    if (my_path == NULL) {
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2053
      warning("Cannot create heap dump file.  Out of system memory.");
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2054
      return;
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2055
    }
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2056
    jio_snprintf(my_path, len, "%s.%d", base_path, dump_file_seq);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2057
  }
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2058
  dump_file_seq++;   // increment seq number for next time we dump
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2059
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2060
  HeapDumper dumper(false /* no GC before heap dump */,
6445
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  2061
                    true  /* send to tty */,
64694b1e56e7 6765718: Indicate which thread throwing OOME when generating the heap dump at OOME
thurka
parents: 5547
diff changeset
  2062
                    oome  /* pass along out-of-memory-error flag */);
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1893
diff changeset
  2063
  dumper.dump(my_path);
7914
6a0f3ba90b09 6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
coleenp
parents: 7397
diff changeset
  2064
  os::free(my_path);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2065
}