hotspot/src/share/vm/services/attachListener.cpp
author coleenp
Mon, 01 Dec 2014 12:16:15 -0500
changeset 27880 afb974a04396
parent 25959 6c11a6272b60
child 29081 c61eb4914428
child 28949 c6f50d62ecef
permissions -rw-r--r--
8060074: os::free() takes MemoryTrackingLevel but doesn't need it Summary: Cleaned up unused arguments in os::free and it's callers. Reviewed-by: lfoltan, coleenp, ctornqvi, dholmes Contributed-by: max.ockner@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22758
diff changeset
     2
 * Copyright (c) 2005, 2014, 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: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "classfile/javaClasses.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "gc_implementation/shared/vmGCOperations.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "prims/jvmtiExport.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "runtime/arguments.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/globals.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "runtime/javaCalls.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "runtime/os.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "services/attachListener.hpp"
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 8921
diff changeset
    37
#include "services/diagnosticCommand.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    38
#include "services/heapDumper.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
volatile bool AttachListener::_initialized;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// Implementation of "properties" command.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// Invokes sun.misc.VMSupport.serializePropertiesToByteArray to serialize
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// the system properties into a byte array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    47
static Klass* load_and_initialize_klass(Symbol* sh, TRAPS) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    48
  Klass* k = SystemDictionary::resolve_or_fail(sh, true, CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  instanceKlassHandle ik (THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  if (ik->should_be_initialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    ik->initialize(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  return ik();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    56
static jint get_properties(AttachOperation* op, outputStream* out, Symbol* serializePropertiesMethod) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  Thread* THREAD = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  HandleMark hm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // load sun.misc.VMSupport
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    61
  Symbol* klass = vmSymbols::sun_misc_VMSupport();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    62
  Klass* k = load_and_initialize_klass(klass, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    java_lang_Throwable::print(PENDING_EXCEPTION, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  instanceKlassHandle ik(THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // invoke the serializePropertiesToByteArray method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  JavaValue result(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  JavaCallArguments args;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    75
  Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  JavaCalls::call_static(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
                           ik,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
                           serializePropertiesMethod,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
                           signature,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
                           &args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
                           THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    java_lang_Throwable::print(PENDING_EXCEPTION, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // The result should be a [B
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  oop res = (oop)result.get_jobject();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  assert(res->is_typeArray(), "just checking");
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13728
diff changeset
    91
  assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // copy the bytes to the output stream
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  typeArrayOop ba = typeArrayOop(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  jbyte* addr = typeArrayOop(res)->byte_at_addr(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  out->print_raw((const char*)addr, ba->length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  return JNI_OK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
// Implementation of "properties" command.
11441
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   102
// See also: PrintSystemPropertiesDCmd class
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
static jint get_system_properties(AttachOperation* op, outputStream* out) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   104
  return get_properties(op, out, vmSymbols::serializePropertiesToByteArray_name());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
// Implementation of "agent_properties" command.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
static jint get_agent_properties(AttachOperation* op, outputStream* out) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   109
  return get_properties(op, out, vmSymbols::serializeAgentPropertiesToByteArray_name());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
// Implementation of "datadump" command.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
// Raises a SIGBREAK signal so that VM dump threads, does deadlock detection,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
// etc. In theory this command should only post a DataDumpRequest to any
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// JVMTI environment that has enabled this event. However it's useful to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
// trigger the SIGBREAK handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
static jint data_dump(AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  if (!ReduceSignalUsage) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    AttachListener::pd_data_dump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    if (JvmtiExport::should_post_data_dump()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      JvmtiExport::post_data_dump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  return JNI_OK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
// Implementation of "threaddump" command - essentially a remote ctrl-break
11441
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   131
// See also: ThreadDumpDCmd class
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
static jint thread_dump(AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  bool print_concurrent_locks = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  if (op->arg(0) != NULL && strcmp(op->arg(0), "-l") == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    print_concurrent_locks = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // thread stacks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  VM_PrintThreads op1(out, print_concurrent_locks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  VMThread::execute(&op1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  // JNI global handles
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  VM_PrintJNI op2(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  VMThread::execute(&op2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  // Deadlock detection
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  VM_FindDeadlocks op3(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  VMThread::execute(&op3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  return JNI_OK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 8921
diff changeset
   154
// A jcmd attach operation request was received, which will now
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 8921
diff changeset
   155
// dispatch to the diagnostic commands used for serviceability functions.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 8921
diff changeset
   156
static jint jcmd(AttachOperation* op, outputStream* out) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 8921
diff changeset
   157
  Thread* THREAD = Thread::current();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 8921
diff changeset
   158
  // All the supplied jcmd arguments are stored as a single
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 8921
diff changeset
   159
  // string (op->arg(0)). This is parsed by the Dcmd framework.
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 15432
diff changeset
   160
  DCmd::parse_and_execute(DCmd_Source_AttachAPI, out, op->arg(0), ' ', THREAD);
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 8921
diff changeset
   161
  if (HAS_PENDING_EXCEPTION) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 8921
diff changeset
   162
    java_lang_Throwable::print(PENDING_EXCEPTION, out);
11441
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   163
    out->cr();
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 8921
diff changeset
   164
    CLEAR_PENDING_EXCEPTION;
24833
c55a7c2888f6 8044398: Attach code should propagate errors in Diagnostic Commands as errors
sla
parents: 24424
diff changeset
   165
    return JNI_ERR;
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 8921
diff changeset
   166
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 8921
diff changeset
   167
  return JNI_OK;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 8921
diff changeset
   168
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 8921
diff changeset
   169
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
// Implementation of "dumpheap" command.
11441
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   171
// See also: HeapDumpDCmd class
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
// Input arguments :-
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
//   arg0: Name of the dump file
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
//   arg1: "-live" or "-all"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
jint dump_heap(AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  const char* path = op->arg(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  if (path == NULL || path[0] == '\0') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    out->print_cr("No dump file specified");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    bool live_objects_only = true;   // default is true to retain the behavior before this change is made
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    const char* arg1 = op->arg(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    if (arg1 != NULL && (strlen(arg1) > 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
      if (strcmp(arg1, "-all") != 0 && strcmp(arg1, "-live") != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
        out->print_cr("Invalid argument to dumpheap operation: %s", arg1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
        return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      live_objects_only = strcmp(arg1, "-live") == 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    // Request a full GC before heap dump if live_objects_only = true
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    // This helps reduces the amount of unreachable objects in the dump
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    // and makes it easier to browse.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    HeapDumper dumper(live_objects_only /* request GC */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    int res = dumper.dump(op->arg(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    if (res == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      out->print_cr("Heap dump file created");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      // heap dump failed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      char* error = dumper.error_as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      if (error == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
        out->print_cr("Dump failed - reason unknown");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
        out->print_cr("%s", error);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  return JNI_OK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
// Implementation of "inspectheap" command
11441
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   213
// See also: ClassHistogramDCmd class
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
// Input arguments :-
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
//   arg0: "-live" or "-all"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
static jint heap_inspection(AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  bool live_objects_only = true;   // default is true to retain the behavior before this change is made
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  const char* arg0 = op->arg(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  if (arg0 != NULL && (strlen(arg0) > 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    if (strcmp(arg0, "-all") != 0 && strcmp(arg0, "-live") != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      out->print_cr("Invalid argument to inspectheap operation: %s", arg0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    live_objects_only = strcmp(arg0, "-live") == 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  }
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17296
diff changeset
   227
  VM_GC_HeapInspection heapop(out, live_objects_only /* request full gc */);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  VMThread::execute(&heapop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  return JNI_OK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
// set a boolean global flag using value from AttachOperation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
static jint set_bool_flag(const char* name, AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  bool value = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  const char* arg1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  if ((arg1 = op->arg(1)) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    int tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    int n = sscanf(arg1, "%d", &tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    if (n != 1) {
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   240
      out->print_cr("flag value must be a boolean (1 or 0)");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    value = (tmp != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  }
20288
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 18025
diff changeset
   245
  bool res = CommandLineFlags::boolAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  if (! res) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    out->print_cr("setting flag %s failed", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  return res? JNI_OK : JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
// set a intx global flag using value from AttachOperation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
static jint set_intx_flag(const char* name, AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  intx value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  const char* arg1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  if ((arg1 = op->arg(1)) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    int n = sscanf(arg1, INTX_FORMAT, &value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    if (n != 1) {
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   259
      out->print_cr("flag value must be an integer");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  }
20288
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 18025
diff changeset
   263
  bool res = CommandLineFlags::intxAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  if (! res) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    out->print_cr("setting flag %s failed", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  return res? JNI_OK : JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
// set a uintx global flag using value from AttachOperation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
static jint set_uintx_flag(const char* name, AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  uintx value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  const char* arg1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  if ((arg1 = op->arg(1)) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    int n = sscanf(arg1, UINTX_FORMAT, &value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    if (n != 1) {
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   278
      out->print_cr("flag value must be an unsigned integer");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
      return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  }
22555
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22197
diff changeset
   282
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22197
diff changeset
   283
  if (strncmp(name, "MaxHeapFreeRatio", 17) == 0) {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22758
diff changeset
   284
    FormatBuffer<80> err_msg("%s", "");
22555
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22197
diff changeset
   285
    if (!Arguments::verify_MaxHeapFreeRatio(err_msg, value)) {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22758
diff changeset
   286
      out->print_cr("%s", err_msg.buffer());
22555
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22197
diff changeset
   287
      return JNI_ERR;
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22197
diff changeset
   288
    }
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22197
diff changeset
   289
  } else if (strncmp(name, "MinHeapFreeRatio", 17) == 0) {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22758
diff changeset
   290
    FormatBuffer<80> err_msg("%s", "");
22555
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22197
diff changeset
   291
    if (!Arguments::verify_MinHeapFreeRatio(err_msg, value)) {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22758
diff changeset
   292
      out->print_cr("%s", err_msg.buffer());
22555
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22197
diff changeset
   293
      return JNI_ERR;
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22197
diff changeset
   294
    }
ea32f6c51d08 8028391: Make the Min/MaxHeapFreeRatio flags manageable
jwilhelm
parents: 22197
diff changeset
   295
  }
20288
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 18025
diff changeset
   296
  bool res = CommandLineFlags::uintxAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   297
  if (! res) {
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   298
    out->print_cr("setting flag %s failed", name);
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   299
  }
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   300
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   301
  return res? JNI_OK : JNI_ERR;
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   302
}
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   303
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   304
// set a uint64_t global flag using value from AttachOperation
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   305
static jint set_uint64_t_flag(const char* name, AttachOperation* op, outputStream* out) {
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   306
  uint64_t value;
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   307
  const char* arg1;
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   308
  if ((arg1 = op->arg(1)) != NULL) {
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   309
    int n = sscanf(arg1, UINT64_FORMAT, &value);
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   310
    if (n != 1) {
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   311
      out->print_cr("flag value must be an unsigned 64-bit integer");
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   312
      return JNI_ERR;
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   313
    }
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   314
  }
20288
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 18025
diff changeset
   315
  bool res = CommandLineFlags::uint64_tAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  if (! res) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    out->print_cr("setting flag %s failed", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  return res? JNI_OK : JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
25959
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   323
// set a size_t global flag using value from AttachOperation
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   324
static jint set_size_t_flag(const char* name, AttachOperation* op, outputStream* out) {
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   325
  size_t value;
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   326
  const char* arg1;
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   327
  if ((arg1 = op->arg(1)) != NULL) {
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   328
    int n = sscanf(arg1, SIZE_FORMAT, &value);
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   329
    if (n != 1) {
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   330
      out->print_cr("flag value must be an unsigned integer");
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   331
      return JNI_ERR;
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   332
    }
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   333
  }
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   334
  bool res = CommandLineFlags::size_tAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   335
  if (! res) {
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   336
    out->print_cr("setting flag %s failed", name);
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   337
  }
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   338
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   339
  return res? JNI_OK : JNI_ERR;
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   340
}
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   341
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
// set a string global flag using value from AttachOperation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
static jint set_ccstr_flag(const char* name, AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  const char* value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  if ((value = op->arg(1)) == NULL) {
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   346
    out->print_cr("flag value must be a string");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  }
20288
e2d549f40de9 8024545: make develop and notproduct flag values available in product builds
twisti
parents: 18025
diff changeset
   349
  bool res = CommandLineFlags::ccstrAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  if (res) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 25959
diff changeset
   351
    FREE_C_HEAP_ARRAY(char, value);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    out->print_cr("setting flag %s failed", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  return res? JNI_OK : JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
// Implementation of "setflag" command
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
static jint set_flag(AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  const char* name = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  if ((name = op->arg(0)) == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    out->print_cr("flag name is missing");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  Flag* f = Flag::find_flag((char*)name, strlen(name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  if (f && f->is_external() && f->is_writeable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    if (f->is_bool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
      return set_bool_flag(name, op, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    } else if (f->is_intx()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
      return set_intx_flag(name, op, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    } else if (f->is_uintx()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
      return set_uintx_flag(name, op, out);
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   376
    } else if (f->is_uint64_t()) {
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   377
      return set_uint64_t_flag(name, op, out);
25959
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   378
    } else if (f->is_size_t()) {
6c11a6272b60 8054823: Add size_t as a valid VM flag type
stefank
parents: 24833
diff changeset
   379
      return set_size_t_flag(name, op, out);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    } else if (f->is_ccstr()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
      return set_ccstr_flag(name, op, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
      return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    return AttachListener::pd_set_flag(op, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
// Implementation of "printflag" command
11441
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   392
// See also: PrintVMFlagsDCmd class
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
static jint print_flag(AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  const char* name = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  if ((name = op->arg(0)) == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    out->print_cr("flag name is missing");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  Flag* f = Flag::find_flag((char*)name, strlen(name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  if (f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    f->print_as_flag(out);
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22758
diff changeset
   402
    out->cr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    out->print_cr("no such flag '%s'", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  return JNI_OK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
// Table to map operation names to functions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
// names must be of length <= AttachOperation::name_length_max
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
static AttachOperationFunctionInfo funcs[] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  { "agentProperties",  get_agent_properties },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  { "datadump",         data_dump },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  { "dumpheap",         dump_heap },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  { "load",             JvmtiExport::load_agent_library },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  { "properties",       get_system_properties },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  { "threaddump",       thread_dump },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  { "inspectheap",      heap_inspection },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  { "setflag",          set_flag },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  { "printflag",        print_flag },
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents: 8921
diff changeset
   422
  { "jcmd",             jcmd },
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  { NULL,               NULL }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
// The Attach Listener threads services a queue. It dequeues an operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
// from the queue, examines the operation name (command), and dispatches
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
// to the corresponding function to perform the operation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
static void attach_listener_thread_entry(JavaThread* thread, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  os::set_priority(thread, NearMaxPriority);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13952
diff changeset
   435
  thread->record_stack_base_and_size();
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 13952
diff changeset
   436
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  if (AttachListener::pd_init() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  AttachListener::set_initialized();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  for (;;) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    AttachOperation* op = AttachListener::dequeue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    if (op == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
      return;   // dequeue failed or shutdown
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    bufferedStream st;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    jint res = JNI_OK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    // handle special detachall operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    if (strcmp(op->name(), AttachOperation::detachall_operation_name()) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
      AttachListener::detachall();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
      // find the function to dispatch too
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
      AttachOperationFunctionInfo* info = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
      for (int i=0; funcs[i].name != NULL; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
        const char* name = funcs[i].name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
        assert(strlen(name) <= AttachOperation::name_length_max, "operation <= name_length_max");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
        if (strcmp(op->name(), name) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
          info = &(funcs[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
          break;
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
      // check for platform dependent attach operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
      if (info == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
        info = AttachListener::pd_find_operation(op->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
      if (info != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
        // dispatch to the function that implements this operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
        res = (info->func)(op, &st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
        st.print("Operation %s not recognized!", op->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
        res = JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    // operation complete - send result and output to client
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    op->complete(res, &st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
22197
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   486
bool AttachListener::has_init_error(TRAPS) {
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   487
  if (HAS_PENDING_EXCEPTION) {
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   488
    tty->print_cr("Exception in VM (AttachListener::init) : ");
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   489
    java_lang_Throwable::print(PENDING_EXCEPTION, tty);
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   490
    tty->cr();
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   491
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   492
    CLEAR_PENDING_EXCEPTION;
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   493
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   494
    return true;
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   495
  } else {
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   496
    return false;
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   497
  }
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   498
}
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   499
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
// Starts the Attach Listener thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
void AttachListener::init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  EXCEPTION_MARK;
22197
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   503
  Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, THREAD);
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   504
  if (has_init_error(THREAD)) {
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   505
    return;
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   506
  }
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   507
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  instanceKlassHandle klass (THREAD, k);
22197
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   509
  instanceHandle thread_oop = klass->allocate_instance_handle(THREAD);
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   510
  if (has_init_error(THREAD)) {
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   511
    return;
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   512
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  const char thread_name[] = "Attach Listener";
22197
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   515
  Handle string = java_lang_String::create_from_str(thread_name, THREAD);
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   516
  if (has_init_error(THREAD)) {
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   517
    return;
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   518
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  // Initialize thread_oop to put it into the system threadGroup
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  Handle thread_group (THREAD, Universe::system_thread_group());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  JavaValue result(T_VOID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  JavaCalls::call_special(&result, thread_oop,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
                       klass,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   525
                       vmSymbols::object_initializer_name(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   526
                       vmSymbols::threadgroup_string_void_signature(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
                       thread_group,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
                       string,
20067
e0337f5f9f5a 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 18025
diff changeset
   529
                       THREAD);
e0337f5f9f5a 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 18025
diff changeset
   530
22197
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   531
  if (has_init_error(THREAD)) {
20067
e0337f5f9f5a 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 18025
diff changeset
   532
    return;
e0337f5f9f5a 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 18025
diff changeset
   533
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4437
diff changeset
   535
  KlassHandle group(THREAD, SystemDictionary::ThreadGroup_klass());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  JavaCalls::call_special(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
                        thread_group,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
                        group,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   539
                        vmSymbols::add_method_name(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   540
                        vmSymbols::thread_void_signature(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
                        thread_oop,             // ARG 1
20067
e0337f5f9f5a 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 18025
diff changeset
   542
                        THREAD);
22197
41ea552a447d 6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents: 20291
diff changeset
   543
  if (has_init_error(THREAD)) {
20067
e0337f5f9f5a 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 18025
diff changeset
   544
    return;
e0337f5f9f5a 6989981: jstack causes "fatal error: ExceptionMark destructor expects no pending exceptions"
sla
parents: 18025
diff changeset
   545
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  { MutexLocker mu(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    JavaThread* listener_thread = new JavaThread(&attach_listener_thread_entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
    // Check that thread and osthread were created
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
    if (listener_thread == NULL || listener_thread->osthread() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
      vm_exit_during_initialization("java.lang.OutOfMemoryError",
22758
c6b6abb73544 7182040: volano29 limited by os resource on Linux - need better diagnostic message
iklam
parents: 22555
diff changeset
   553
                                    os::native_thread_creation_failed_msg());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    java_lang_Thread::set_thread(thread_oop(), listener_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
    java_lang_Thread::set_daemon(thread_oop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
    listener_thread->set_threadObj(thread_oop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    Threads::add(listener_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    Thread::start(listener_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
// Performs clean-up tasks on platforms where we can detect that the last
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
// client has detached
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
void AttachListener::detachall() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  // call the platform dependent clean-up
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  pd_detachall();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
}