hotspot/src/share/vm/services/attachListener.cpp
author never
Wed, 06 Jan 2010 14:22:39 -0800
changeset 4571 80b553bddc26
parent 4437 d1abc17afffb
child 5547 f4b087cbb361
permissions -rw-r--r--
6914300: ciEnv should export all well known classes Reviewed-by: kvn, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_attachListener.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
volatile bool AttachListener::_initialized;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// Implementation of "properties" command.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// Invokes sun.misc.VMSupport.serializePropertiesToByteArray to serialize
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// the system properties into a byte array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
static klassOop load_and_initialize_klass(symbolHandle sh, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  klassOop k = SystemDictionary::resolve_or_fail(sh, true, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  instanceKlassHandle ik (THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  if (ik->should_be_initialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    ik->initialize(CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  return ik();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
static jint get_properties(AttachOperation* op, outputStream* out, symbolHandle serializePropertiesMethod) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  Thread* THREAD = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  HandleMark hm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // load sun.misc.VMSupport
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  symbolHandle klass = vmSymbolHandles::sun_misc_VMSupport();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  klassOop k = load_and_initialize_klass(klass, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    java_lang_Throwable::print(PENDING_EXCEPTION, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  instanceKlassHandle ik(THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // invoke the serializePropertiesToByteArray method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  JavaValue result(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  JavaCallArguments args;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  symbolHandle signature = vmSymbolHandles::serializePropertiesToByteArray_signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  JavaCalls::call_static(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
                           ik,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
                           serializePropertiesMethod,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
                           signature,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
                           &args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
                           THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    java_lang_Throwable::print(PENDING_EXCEPTION, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // The result should be a [B
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  oop res = (oop)result.get_jobject();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  assert(res->is_typeArray(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  assert(typeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // copy the bytes to the output stream
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  typeArrayOop ba = typeArrayOop(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  jbyte* addr = typeArrayOop(res)->byte_at_addr(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  out->print_raw((const char*)addr, ba->length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  return JNI_OK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
// Implementation of "properties" command.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
static jint get_system_properties(AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  return get_properties(op, out, vmSymbolHandles::serializePropertiesToByteArray_name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
// Implementation of "agent_properties" command.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
static jint get_agent_properties(AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  return get_properties(op, out, vmSymbolHandles::serializeAgentPropertiesToByteArray_name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
// Implementation of "datadump" command.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
// Raises a SIGBREAK signal so that VM dump threads, does deadlock detection,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
// etc. In theory this command should only post a DataDumpRequest to any
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
// JVMTI environment that has enabled this event. However it's useful to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
// trigger the SIGBREAK handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
static jint data_dump(AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  if (!ReduceSignalUsage) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    AttachListener::pd_data_dump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    if (JvmtiExport::should_post_data_dump()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      JvmtiExport::post_data_dump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  return JNI_OK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
// Implementation of "threaddump" command - essentially a remote ctrl-break
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
static jint thread_dump(AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  bool print_concurrent_locks = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  if (op->arg(0) != NULL && strcmp(op->arg(0), "-l") == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    print_concurrent_locks = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // thread stacks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  VM_PrintThreads op1(out, print_concurrent_locks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  VMThread::execute(&op1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // JNI global handles
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  VM_PrintJNI op2(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  VMThread::execute(&op2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // Deadlock detection
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  VM_FindDeadlocks op3(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  VMThread::execute(&op3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  return JNI_OK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
#ifndef SERVICES_KERNEL   // Heap dumping not supported
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
// Implementation of "dumpheap" command.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
// Input arguments :-
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
//   arg0: Name of the dump file
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
//   arg1: "-live" or "-all"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
jint dump_heap(AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  const char* path = op->arg(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  if (path == NULL || path[0] == '\0') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    out->print_cr("No dump file specified");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    bool live_objects_only = true;   // default is true to retain the behavior before this change is made
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    const char* arg1 = op->arg(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    if (arg1 != NULL && (strlen(arg1) > 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      if (strcmp(arg1, "-all") != 0 && strcmp(arg1, "-live") != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        out->print_cr("Invalid argument to dumpheap operation: %s", arg1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
        return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      live_objects_only = strcmp(arg1, "-live") == 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    // Request a full GC before heap dump if live_objects_only = true
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    // This helps reduces the amount of unreachable objects in the dump
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    // and makes it easier to browse.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    HeapDumper dumper(live_objects_only /* request GC */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    int res = dumper.dump(op->arg(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    if (res == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      out->print_cr("Heap dump file created");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      // heap dump failed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      char* error = dumper.error_as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      if (error == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
        out->print_cr("Dump failed - reason unknown");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
        out->print_cr("%s", error);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  return JNI_OK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
#endif // SERVICES_KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
// Implementation of "inspectheap" command
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
// Input arguments :-
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
//   arg0: "-live" or "-all"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
static jint heap_inspection(AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  bool live_objects_only = true;   // default is true to retain the behavior before this change is made
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  const char* arg0 = op->arg(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  if (arg0 != NULL && (strlen(arg0) > 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    if (strcmp(arg0, "-all") != 0 && strcmp(arg0, "-live") != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      out->print_cr("Invalid argument to inspectheap operation: %s", arg0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    live_objects_only = strcmp(arg0, "-live") == 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  }
2141
e9a644aaff87 6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents: 1
diff changeset
   197
  VM_GC_HeapInspection heapop(out, live_objects_only /* request full gc */, true /* need_prologue */);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  VMThread::execute(&heapop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  return JNI_OK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
// set a boolean global flag using value from AttachOperation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
static jint set_bool_flag(const char* name, AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  bool value = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  const char* arg1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  if ((arg1 = op->arg(1)) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    int tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    int n = sscanf(arg1, "%d", &tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    if (n != 1) {
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   210
      out->print_cr("flag value must be a boolean (1 or 0)");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
      return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    value = (tmp != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  bool res = CommandLineFlags::boolAtPut((char*)name, &value, ATTACH_ON_DEMAND);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  if (! res) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    out->print_cr("setting flag %s failed", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  return res? JNI_OK : JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
// set a intx global flag using value from AttachOperation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
static jint set_intx_flag(const char* name, AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  intx value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  const char* arg1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  if ((arg1 = op->arg(1)) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    int n = sscanf(arg1, INTX_FORMAT, &value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    if (n != 1) {
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   229
      out->print_cr("flag value must be an integer");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  }
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   233
  bool res = CommandLineFlags::intxAtPut((char*)name, &value, ATTACH_ON_DEMAND);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  if (! res) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    out->print_cr("setting flag %s failed", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  return res? JNI_OK : JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
// set a uintx global flag using value from AttachOperation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
static jint set_uintx_flag(const char* name, AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  uintx value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  const char* arg1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  if ((arg1 = op->arg(1)) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    int n = sscanf(arg1, UINTX_FORMAT, &value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    if (n != 1) {
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   248
      out->print_cr("flag value must be an unsigned integer");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  }
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   252
  bool res = CommandLineFlags::uintxAtPut((char*)name, &value, ATTACH_ON_DEMAND);
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   253
  if (! res) {
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   254
    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
   255
  }
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   256
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   257
  return res? JNI_OK : JNI_ERR;
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   258
}
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   259
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   260
// 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
   261
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
   262
  uint64_t value;
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   263
  const char* arg1;
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   264
  if ((arg1 = op->arg(1)) != NULL) {
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   265
    int n = sscanf(arg1, UINT64_FORMAT, &value);
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   266
    if (n != 1) {
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   267
      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
   268
      return JNI_ERR;
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   269
    }
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   270
  }
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   271
  bool res = CommandLineFlags::uint64_tAtPut((char*)name, &value, ATTACH_ON_DEMAND);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  if (! res) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    out->print_cr("setting flag %s failed", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  return res? JNI_OK : JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
// set a string global flag using value from AttachOperation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
static jint set_ccstr_flag(const char* name, AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  const char* value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  if ((value = op->arg(1)) == NULL) {
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   283
    out->print_cr("flag value must be a string");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  }
4437
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   286
  bool res = CommandLineFlags::ccstrAtPut((char*)name, &value, ATTACH_ON_DEMAND);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  if (res) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    FREE_C_HEAP_ARRAY(char, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    out->print_cr("setting flag %s failed", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  return res? JNI_OK : JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
// Implementation of "setflag" command
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
static jint set_flag(AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  const char* name = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  if ((name = op->arg(0)) == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    out->print_cr("flag name is missing");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  Flag* f = Flag::find_flag((char*)name, strlen(name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  if (f && f->is_external() && f->is_writeable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    if (f->is_bool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
      return set_bool_flag(name, op, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    } else if (f->is_intx()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
      return set_intx_flag(name, op, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    } else if (f->is_uintx()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
      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
   313
    } else if (f->is_uint64_t()) {
d1abc17afffb 6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents: 2141
diff changeset
   314
      return set_uint64_t_flag(name, op, out);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    } else if (f->is_ccstr()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      return set_ccstr_flag(name, op, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    return AttachListener::pd_set_flag(op, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
// Implementation of "printflag" command
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
static jint print_flag(AttachOperation* op, outputStream* out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  const char* name = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  if ((name = op->arg(0)) == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    out->print_cr("flag name is missing");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    return JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  Flag* f = Flag::find_flag((char*)name, strlen(name));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  if (f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    f->print_as_flag(out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    out->print_cr("");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    out->print_cr("no such flag '%s'", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  return JNI_OK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
// Table to map operation names to functions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
// names must be of length <= AttachOperation::name_length_max
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
static AttachOperationFunctionInfo funcs[] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  { "agentProperties",  get_agent_properties },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  { "datadump",         data_dump },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
#ifndef SERVICES_KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  { "dumpheap",         dump_heap },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
#endif  // SERVICES_KERNEL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  { "load",             JvmtiExport::load_agent_library },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  { "properties",       get_system_properties },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  { "threaddump",       thread_dump },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  { "inspectheap",      heap_inspection },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  { "setflag",          set_flag },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  { "printflag",        print_flag },
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  { NULL,               NULL }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
// The Attach Listener threads services a queue. It dequeues an operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
// from the queue, examines the operation name (command), and dispatches
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
// to the corresponding function to perform the operation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
static void attach_listener_thread_entry(JavaThread* thread, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  os::set_priority(thread, NearMaxPriority);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  if (AttachListener::pd_init() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  AttachListener::set_initialized();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  for (;;) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    AttachOperation* op = AttachListener::dequeue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    if (op == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
      return;   // dequeue failed or shutdown
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    bufferedStream st;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    jint res = JNI_OK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    // handle special detachall operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    if (strcmp(op->name(), AttachOperation::detachall_operation_name()) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
      AttachListener::detachall();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
      // find the function to dispatch too
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
      AttachOperationFunctionInfo* info = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      for (int i=0; funcs[i].name != NULL; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
        const char* name = funcs[i].name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
        assert(strlen(name) <= AttachOperation::name_length_max, "operation <= name_length_max");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
        if (strcmp(op->name(), name) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
          info = &(funcs[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
      // check for platform dependent attach operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
      if (info == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
        info = AttachListener::pd_find_operation(op->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
      if (info != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
        // dispatch to the function that implements this operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
        res = (info->func)(op, &st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
        st.print("Operation %s not recognized!", op->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
        res = JNI_ERR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    // operation complete - send result and output to client
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    op->complete(res, &st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
// Starts the Attach Listener thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
void AttachListener::init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  klassOop k = SystemDictionary::resolve_or_fail(vmSymbolHandles::java_lang_Thread(), true, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  instanceKlassHandle klass (THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  instanceHandle thread_oop = klass->allocate_instance_handle(CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  const char thread_name[] = "Attach Listener";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  Handle string = java_lang_String::create_from_str(thread_name, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  // Initialize thread_oop to put it into the system threadGroup
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  Handle thread_group (THREAD, Universe::system_thread_group());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  JavaValue result(T_VOID);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  JavaCalls::call_special(&result, thread_oop,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
                       klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
                       vmSymbolHandles::object_initializer_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
                       vmSymbolHandles::threadgroup_string_void_signature(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
                       thread_group,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
                       string,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
                       CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4437
diff changeset
   440
  KlassHandle group(THREAD, SystemDictionary::ThreadGroup_klass());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  JavaCalls::call_special(&result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
                        thread_group,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
                        group,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
                        vmSymbolHandles::add_method_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
                        vmSymbolHandles::thread_void_signature(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
                        thread_oop,             // ARG 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
                        CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  { MutexLocker mu(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    JavaThread* listener_thread = new JavaThread(&attach_listener_thread_entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    // Check that thread and osthread were created
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    if (listener_thread == NULL || listener_thread->osthread() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
      vm_exit_during_initialization("java.lang.OutOfMemoryError",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
                                    "unable to create new native thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
    java_lang_Thread::set_thread(thread_oop(), listener_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
    java_lang_Thread::set_daemon(thread_oop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
    listener_thread->set_threadObj(thread_oop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    Threads::add(listener_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    Thread::start(listener_thread);
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
// Performs clean-up tasks on platforms where we can detect that the last
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
// client has detached
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
void AttachListener::detachall() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  // call the platform dependent clean-up
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  pd_detachall();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
}