src/share/vm/services/attachListener.cpp

Tue, 31 Dec 2013 08:58:08 -0500

author
zgu
date
Tue, 31 Dec 2013 08:58:08 -0500
changeset 9313
fd0ca2c1433b
parent 8658
f8a5d01c0929
child 9448
73d689add964
permissions
-rw-r--r--

6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
Summary: Fixed incompatible uses of EXCEPTION_MARK and CHECK macros in AttachListener::init(), handle exception locally.
Reviewed-by: minqi, coleenp

duke@435 1 /*
dsamersoff@8658 2 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/javaClasses.hpp"
stefank@2314 27 #include "classfile/systemDictionary.hpp"
stefank@2314 28 #include "gc_implementation/shared/vmGCOperations.hpp"
stefank@2314 29 #include "memory/resourceArea.hpp"
stefank@2314 30 #include "prims/jvmtiExport.hpp"
stefank@2314 31 #include "runtime/arguments.hpp"
stefank@2314 32 #include "runtime/globals.hpp"
stefank@2314 33 #include "runtime/java.hpp"
stefank@2314 34 #include "runtime/javaCalls.hpp"
stefank@2314 35 #include "runtime/os.hpp"
stefank@2314 36 #include "services/attachListener.hpp"
fparain@3329 37 #include "services/diagnosticCommand.hpp"
stefank@2314 38 #include "services/heapDumper.hpp"
duke@435 39
duke@435 40 volatile bool AttachListener::_initialized;
duke@435 41
duke@435 42 // Implementation of "properties" command.
duke@435 43 //
duke@435 44 // Invokes sun.misc.VMSupport.serializePropertiesToByteArray to serialize
duke@435 45 // the system properties into a byte array.
duke@435 46
coleenp@4037 47 static Klass* load_and_initialize_klass(Symbol* sh, TRAPS) {
coleenp@4037 48 Klass* k = SystemDictionary::resolve_or_fail(sh, true, CHECK_NULL);
duke@435 49 instanceKlassHandle ik (THREAD, k);
duke@435 50 if (ik->should_be_initialized()) {
duke@435 51 ik->initialize(CHECK_NULL);
duke@435 52 }
duke@435 53 return ik();
duke@435 54 }
duke@435 55
coleenp@2497 56 static jint get_properties(AttachOperation* op, outputStream* out, Symbol* serializePropertiesMethod) {
duke@435 57 Thread* THREAD = Thread::current();
duke@435 58 HandleMark hm;
duke@435 59
duke@435 60 // load sun.misc.VMSupport
coleenp@2497 61 Symbol* klass = vmSymbols::sun_misc_VMSupport();
coleenp@4037 62 Klass* k = load_and_initialize_klass(klass, THREAD);
duke@435 63 if (HAS_PENDING_EXCEPTION) {
duke@435 64 java_lang_Throwable::print(PENDING_EXCEPTION, out);
duke@435 65 CLEAR_PENDING_EXCEPTION;
duke@435 66 return JNI_ERR;
duke@435 67 }
duke@435 68 instanceKlassHandle ik(THREAD, k);
duke@435 69
duke@435 70 // invoke the serializePropertiesToByteArray method
duke@435 71 JavaValue result(T_OBJECT);
duke@435 72 JavaCallArguments args;
duke@435 73
duke@435 74
coleenp@2497 75 Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature();
duke@435 76 JavaCalls::call_static(&result,
duke@435 77 ik,
duke@435 78 serializePropertiesMethod,
duke@435 79 signature,
duke@435 80 &args,
duke@435 81 THREAD);
duke@435 82 if (HAS_PENDING_EXCEPTION) {
duke@435 83 java_lang_Throwable::print(PENDING_EXCEPTION, out);
duke@435 84 CLEAR_PENDING_EXCEPTION;
duke@435 85 return JNI_ERR;
duke@435 86 }
duke@435 87
duke@435 88 // The result should be a [B
duke@435 89 oop res = (oop)result.get_jobject();
duke@435 90 assert(res->is_typeArray(), "just checking");
coleenp@4142 91 assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking");
duke@435 92
duke@435 93 // copy the bytes to the output stream
duke@435 94 typeArrayOop ba = typeArrayOop(res);
duke@435 95 jbyte* addr = typeArrayOop(res)->byte_at_addr(0);
duke@435 96 out->print_raw((const char*)addr, ba->length());
duke@435 97
duke@435 98 return JNI_OK;
duke@435 99 }
duke@435 100
duke@435 101 // Implementation of "properties" command.
fparain@3402 102 // See also: PrintSystemPropertiesDCmd class
duke@435 103 static jint get_system_properties(AttachOperation* op, outputStream* out) {
coleenp@2497 104 return get_properties(op, out, vmSymbols::serializePropertiesToByteArray_name());
duke@435 105 }
duke@435 106
duke@435 107 // Implementation of "agent_properties" command.
duke@435 108 static jint get_agent_properties(AttachOperation* op, outputStream* out) {
coleenp@2497 109 return get_properties(op, out, vmSymbols::serializeAgentPropertiesToByteArray_name());
duke@435 110 }
duke@435 111
duke@435 112 // Implementation of "datadump" command.
duke@435 113 //
duke@435 114 // Raises a SIGBREAK signal so that VM dump threads, does deadlock detection,
duke@435 115 // etc. In theory this command should only post a DataDumpRequest to any
duke@435 116 // JVMTI environment that has enabled this event. However it's useful to
duke@435 117 // trigger the SIGBREAK handler.
duke@435 118
duke@435 119 static jint data_dump(AttachOperation* op, outputStream* out) {
duke@435 120 if (!ReduceSignalUsage) {
duke@435 121 AttachListener::pd_data_dump();
duke@435 122 } else {
duke@435 123 if (JvmtiExport::should_post_data_dump()) {
duke@435 124 JvmtiExport::post_data_dump();
duke@435 125 }
duke@435 126 }
duke@435 127 return JNI_OK;
duke@435 128 }
duke@435 129
duke@435 130 // Implementation of "threaddump" command - essentially a remote ctrl-break
fparain@3402 131 // See also: ThreadDumpDCmd class
duke@435 132 //
duke@435 133 static jint thread_dump(AttachOperation* op, outputStream* out) {
duke@435 134 bool print_concurrent_locks = false;
duke@435 135 if (op->arg(0) != NULL && strcmp(op->arg(0), "-l") == 0) {
duke@435 136 print_concurrent_locks = true;
duke@435 137 }
duke@435 138
duke@435 139 // thread stacks
duke@435 140 VM_PrintThreads op1(out, print_concurrent_locks);
duke@435 141 VMThread::execute(&op1);
duke@435 142
duke@435 143 // JNI global handles
duke@435 144 VM_PrintJNI op2(out);
duke@435 145 VMThread::execute(&op2);
duke@435 146
duke@435 147 // Deadlock detection
duke@435 148 VM_FindDeadlocks op3(out);
duke@435 149 VMThread::execute(&op3);
duke@435 150
duke@435 151 return JNI_OK;
duke@435 152 }
duke@435 153
fparain@3329 154 // A jcmd attach operation request was received, which will now
fparain@3329 155 // dispatch to the diagnostic commands used for serviceability functions.
fparain@3329 156 static jint jcmd(AttachOperation* op, outputStream* out) {
fparain@3329 157 Thread* THREAD = Thread::current();
fparain@3329 158 // All the supplied jcmd arguments are stored as a single
fparain@3329 159 // string (op->arg(0)). This is parsed by the Dcmd framework.
fparain@5047 160 DCmd::parse_and_execute(DCmd_Source_AttachAPI, out, op->arg(0), ' ', THREAD);
fparain@3329 161 if (HAS_PENDING_EXCEPTION) {
fparain@3329 162 java_lang_Throwable::print(PENDING_EXCEPTION, out);
fparain@3402 163 out->cr();
fparain@3329 164 CLEAR_PENDING_EXCEPTION;
sla@7128 165 return JNI_ERR;
fparain@3329 166 }
fparain@3329 167 return JNI_OK;
fparain@3329 168 }
fparain@3329 169
duke@435 170 // Implementation of "dumpheap" command.
fparain@3402 171 // See also: HeapDumpDCmd class
duke@435 172 //
duke@435 173 // Input arguments :-
duke@435 174 // arg0: Name of the dump file
duke@435 175 // arg1: "-live" or "-all"
duke@435 176 jint dump_heap(AttachOperation* op, outputStream* out) {
duke@435 177 const char* path = op->arg(0);
duke@435 178 if (path == NULL || path[0] == '\0') {
duke@435 179 out->print_cr("No dump file specified");
duke@435 180 } else {
duke@435 181 bool live_objects_only = true; // default is true to retain the behavior before this change is made
duke@435 182 const char* arg1 = op->arg(1);
duke@435 183 if (arg1 != NULL && (strlen(arg1) > 0)) {
duke@435 184 if (strcmp(arg1, "-all") != 0 && strcmp(arg1, "-live") != 0) {
duke@435 185 out->print_cr("Invalid argument to dumpheap operation: %s", arg1);
duke@435 186 return JNI_ERR;
duke@435 187 }
duke@435 188 live_objects_only = strcmp(arg1, "-live") == 0;
duke@435 189 }
duke@435 190
duke@435 191 // Request a full GC before heap dump if live_objects_only = true
duke@435 192 // This helps reduces the amount of unreachable objects in the dump
duke@435 193 // and makes it easier to browse.
duke@435 194 HeapDumper dumper(live_objects_only /* request GC */);
duke@435 195 int res = dumper.dump(op->arg(0));
duke@435 196 if (res == 0) {
duke@435 197 out->print_cr("Heap dump file created");
duke@435 198 } else {
duke@435 199 // heap dump failed
duke@435 200 ResourceMark rm;
duke@435 201 char* error = dumper.error_as_C_string();
duke@435 202 if (error == NULL) {
duke@435 203 out->print_cr("Dump failed - reason unknown");
duke@435 204 } else {
duke@435 205 out->print_cr("%s", error);
duke@435 206 }
duke@435 207 }
duke@435 208 }
duke@435 209 return JNI_OK;
duke@435 210 }
duke@435 211
duke@435 212 // Implementation of "inspectheap" command
fparain@3402 213 // See also: ClassHistogramDCmd class
duke@435 214 //
duke@435 215 // Input arguments :-
duke@435 216 // arg0: "-live" or "-all"
duke@435 217 static jint heap_inspection(AttachOperation* op, outputStream* out) {
duke@435 218 bool live_objects_only = true; // default is true to retain the behavior before this change is made
duke@435 219 const char* arg0 = op->arg(0);
duke@435 220 if (arg0 != NULL && (strlen(arg0) > 0)) {
duke@435 221 if (strcmp(arg0, "-all") != 0 && strcmp(arg0, "-live") != 0) {
duke@435 222 out->print_cr("Invalid argument to inspectheap operation: %s", arg0);
duke@435 223 return JNI_ERR;
duke@435 224 }
duke@435 225 live_objects_only = strcmp(arg0, "-live") == 0;
duke@435 226 }
sla@5237 227 VM_GC_HeapInspection heapop(out, live_objects_only /* request full gc */);
duke@435 228 VMThread::execute(&heapop);
duke@435 229 return JNI_OK;
duke@435 230 }
duke@435 231
duke@435 232 // set a boolean global flag using value from AttachOperation
duke@435 233 static jint set_bool_flag(const char* name, AttachOperation* op, outputStream* out) {
duke@435 234 bool value = true;
duke@435 235 const char* arg1;
duke@435 236 if ((arg1 = op->arg(1)) != NULL) {
duke@435 237 int tmp;
duke@435 238 int n = sscanf(arg1, "%d", &tmp);
duke@435 239 if (n != 1) {
phh@1502 240 out->print_cr("flag value must be a boolean (1 or 0)");
duke@435 241 return JNI_ERR;
duke@435 242 }
duke@435 243 value = (tmp != 0);
duke@435 244 }
twisti@5790 245 bool res = CommandLineFlags::boolAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
duke@435 246 if (! res) {
duke@435 247 out->print_cr("setting flag %s failed", name);
duke@435 248 }
duke@435 249 return res? JNI_OK : JNI_ERR;
duke@435 250 }
duke@435 251
duke@435 252 // set a intx global flag using value from AttachOperation
duke@435 253 static jint set_intx_flag(const char* name, AttachOperation* op, outputStream* out) {
duke@435 254 intx value;
duke@435 255 const char* arg1;
duke@435 256 if ((arg1 = op->arg(1)) != NULL) {
duke@435 257 int n = sscanf(arg1, INTX_FORMAT, &value);
duke@435 258 if (n != 1) {
phh@1502 259 out->print_cr("flag value must be an integer");
duke@435 260 return JNI_ERR;
duke@435 261 }
duke@435 262 }
twisti@5790 263 bool res = CommandLineFlags::intxAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
duke@435 264 if (! res) {
duke@435 265 out->print_cr("setting flag %s failed", name);
duke@435 266 }
duke@435 267
duke@435 268 return res? JNI_OK : JNI_ERR;
duke@435 269 }
duke@435 270
duke@435 271 // set a uintx global flag using value from AttachOperation
duke@435 272 static jint set_uintx_flag(const char* name, AttachOperation* op, outputStream* out) {
duke@435 273 uintx value;
dsamersoff@8658 274
dsamersoff@8658 275 const char* arg1 = op->arg(1);
dsamersoff@8658 276 if (arg1 == NULL) {
dsamersoff@8658 277 out->print_cr("flag value must be specified");
dsamersoff@8658 278 return JNI_ERR;
dsamersoff@8658 279 }
dsamersoff@8658 280
dsamersoff@8658 281 int n = sscanf(arg1, UINTX_FORMAT, &value);
dsamersoff@8658 282 if (n != 1) {
dsamersoff@8658 283 out->print_cr("flag value must be an unsigned integer");
dsamersoff@8658 284 return JNI_ERR;
duke@435 285 }
jwilhelm@6267 286
jwilhelm@6267 287 if (strncmp(name, "MaxHeapFreeRatio", 17) == 0) {
drchase@6680 288 FormatBuffer<80> err_msg("%s", "");
jwilhelm@6267 289 if (!Arguments::verify_MaxHeapFreeRatio(err_msg, value)) {
drchase@6680 290 out->print_cr("%s", err_msg.buffer());
jwilhelm@6267 291 return JNI_ERR;
jwilhelm@6267 292 }
jwilhelm@6267 293 } else if (strncmp(name, "MinHeapFreeRatio", 17) == 0) {
drchase@6680 294 FormatBuffer<80> err_msg("%s", "");
jwilhelm@6267 295 if (!Arguments::verify_MinHeapFreeRatio(err_msg, value)) {
drchase@6680 296 out->print_cr("%s", err_msg.buffer());
jwilhelm@6267 297 return JNI_ERR;
jwilhelm@6267 298 }
jwilhelm@6267 299 }
twisti@5790 300 bool res = CommandLineFlags::uintxAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
phh@1502 301 if (! res) {
phh@1502 302 out->print_cr("setting flag %s failed", name);
phh@1502 303 }
phh@1502 304
phh@1502 305 return res? JNI_OK : JNI_ERR;
phh@1502 306 }
phh@1502 307
phh@1502 308 // set a uint64_t global flag using value from AttachOperation
phh@1502 309 static jint set_uint64_t_flag(const char* name, AttachOperation* op, outputStream* out) {
phh@1502 310 uint64_t value;
phh@1502 311 const char* arg1;
phh@1502 312 if ((arg1 = op->arg(1)) != NULL) {
phh@1502 313 int n = sscanf(arg1, UINT64_FORMAT, &value);
phh@1502 314 if (n != 1) {
phh@1502 315 out->print_cr("flag value must be an unsigned 64-bit integer");
phh@1502 316 return JNI_ERR;
phh@1502 317 }
phh@1502 318 }
twisti@5790 319 bool res = CommandLineFlags::uint64_tAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
duke@435 320 if (! res) {
duke@435 321 out->print_cr("setting flag %s failed", name);
duke@435 322 }
duke@435 323
duke@435 324 return res? JNI_OK : JNI_ERR;
duke@435 325 }
duke@435 326
duke@435 327 // set a string global flag using value from AttachOperation
duke@435 328 static jint set_ccstr_flag(const char* name, AttachOperation* op, outputStream* out) {
duke@435 329 const char* value;
duke@435 330 if ((value = op->arg(1)) == NULL) {
phh@1502 331 out->print_cr("flag value must be a string");
duke@435 332 return JNI_ERR;
duke@435 333 }
twisti@5790 334 bool res = CommandLineFlags::ccstrAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
duke@435 335 if (res) {
zgu@3900 336 FREE_C_HEAP_ARRAY(char, value, mtInternal);
duke@435 337 } else {
duke@435 338 out->print_cr("setting flag %s failed", name);
duke@435 339 }
duke@435 340
duke@435 341 return res? JNI_OK : JNI_ERR;
duke@435 342 }
duke@435 343
duke@435 344 // Implementation of "setflag" command
duke@435 345 static jint set_flag(AttachOperation* op, outputStream* out) {
duke@435 346
duke@435 347 const char* name = NULL;
duke@435 348 if ((name = op->arg(0)) == NULL) {
duke@435 349 out->print_cr("flag name is missing");
duke@435 350 return JNI_ERR;
duke@435 351 }
duke@435 352
duke@435 353 Flag* f = Flag::find_flag((char*)name, strlen(name));
duke@435 354 if (f && f->is_external() && f->is_writeable()) {
duke@435 355 if (f->is_bool()) {
duke@435 356 return set_bool_flag(name, op, out);
duke@435 357 } else if (f->is_intx()) {
duke@435 358 return set_intx_flag(name, op, out);
duke@435 359 } else if (f->is_uintx()) {
duke@435 360 return set_uintx_flag(name, op, out);
phh@1502 361 } else if (f->is_uint64_t()) {
phh@1502 362 return set_uint64_t_flag(name, op, out);
duke@435 363 } else if (f->is_ccstr()) {
duke@435 364 return set_ccstr_flag(name, op, out);
duke@435 365 } else {
duke@435 366 ShouldNotReachHere();
duke@435 367 return JNI_ERR;
duke@435 368 }
duke@435 369 } else {
duke@435 370 return AttachListener::pd_set_flag(op, out);
duke@435 371 }
duke@435 372 }
duke@435 373
duke@435 374 // Implementation of "printflag" command
fparain@3402 375 // See also: PrintVMFlagsDCmd class
duke@435 376 static jint print_flag(AttachOperation* op, outputStream* out) {
duke@435 377 const char* name = NULL;
duke@435 378 if ((name = op->arg(0)) == NULL) {
duke@435 379 out->print_cr("flag name is missing");
duke@435 380 return JNI_ERR;
duke@435 381 }
duke@435 382 Flag* f = Flag::find_flag((char*)name, strlen(name));
duke@435 383 if (f) {
duke@435 384 f->print_as_flag(out);
drchase@6680 385 out->cr();
duke@435 386 } else {
duke@435 387 out->print_cr("no such flag '%s'", name);
duke@435 388 }
duke@435 389 return JNI_OK;
duke@435 390 }
duke@435 391
duke@435 392 // Table to map operation names to functions.
duke@435 393
duke@435 394 // names must be of length <= AttachOperation::name_length_max
duke@435 395 static AttachOperationFunctionInfo funcs[] = {
duke@435 396 { "agentProperties", get_agent_properties },
duke@435 397 { "datadump", data_dump },
duke@435 398 { "dumpheap", dump_heap },
duke@435 399 { "load", JvmtiExport::load_agent_library },
duke@435 400 { "properties", get_system_properties },
duke@435 401 { "threaddump", thread_dump },
duke@435 402 { "inspectheap", heap_inspection },
duke@435 403 { "setflag", set_flag },
duke@435 404 { "printflag", print_flag },
fparain@3329 405 { "jcmd", jcmd },
duke@435 406 { NULL, NULL }
duke@435 407 };
duke@435 408
duke@435 409
duke@435 410
duke@435 411 // The Attach Listener threads services a queue. It dequeues an operation
duke@435 412 // from the queue, examines the operation name (command), and dispatches
duke@435 413 // to the corresponding function to perform the operation.
duke@435 414
duke@435 415 static void attach_listener_thread_entry(JavaThread* thread, TRAPS) {
duke@435 416 os::set_priority(thread, NearMaxPriority);
duke@435 417
zgu@4193 418 thread->record_stack_base_and_size();
zgu@4193 419
duke@435 420 if (AttachListener::pd_init() != 0) {
duke@435 421 return;
duke@435 422 }
duke@435 423 AttachListener::set_initialized();
duke@435 424
duke@435 425 for (;;) {
duke@435 426 AttachOperation* op = AttachListener::dequeue();
duke@435 427 if (op == NULL) {
duke@435 428 return; // dequeue failed or shutdown
duke@435 429 }
duke@435 430
duke@435 431 ResourceMark rm;
duke@435 432 bufferedStream st;
duke@435 433 jint res = JNI_OK;
duke@435 434
duke@435 435 // handle special detachall operation
duke@435 436 if (strcmp(op->name(), AttachOperation::detachall_operation_name()) == 0) {
duke@435 437 AttachListener::detachall();
duke@435 438 } else {
duke@435 439 // find the function to dispatch too
duke@435 440 AttachOperationFunctionInfo* info = NULL;
duke@435 441 for (int i=0; funcs[i].name != NULL; i++) {
duke@435 442 const char* name = funcs[i].name;
duke@435 443 assert(strlen(name) <= AttachOperation::name_length_max, "operation <= name_length_max");
duke@435 444 if (strcmp(op->name(), name) == 0) {
duke@435 445 info = &(funcs[i]);
duke@435 446 break;
duke@435 447 }
duke@435 448 }
duke@435 449
duke@435 450 // check for platform dependent attach operation
duke@435 451 if (info == NULL) {
duke@435 452 info = AttachListener::pd_find_operation(op->name());
duke@435 453 }
duke@435 454
duke@435 455 if (info != NULL) {
duke@435 456 // dispatch to the function that implements this operation
duke@435 457 res = (info->func)(op, &st);
duke@435 458 } else {
duke@435 459 st.print("Operation %s not recognized!", op->name());
duke@435 460 res = JNI_ERR;
duke@435 461 }
duke@435 462 }
duke@435 463
duke@435 464 // operation complete - send result and output to client
duke@435 465 op->complete(res, &st);
duke@435 466 }
duke@435 467 }
duke@435 468
zgu@9313 469 bool AttachListener::has_init_error(TRAPS) {
zgu@9313 470 if (HAS_PENDING_EXCEPTION) {
zgu@9313 471 tty->print_cr("Exception in VM (AttachListener::init) : ");
zgu@9313 472 java_lang_Throwable::print(PENDING_EXCEPTION, tty);
zgu@9313 473 tty->cr();
zgu@9313 474
zgu@9313 475 CLEAR_PENDING_EXCEPTION;
zgu@9313 476
zgu@9313 477 return true;
zgu@9313 478 } else {
zgu@9313 479 return false;
zgu@9313 480 }
zgu@9313 481 }
zgu@9313 482
duke@435 483 // Starts the Attach Listener thread
duke@435 484 void AttachListener::init() {
duke@435 485 EXCEPTION_MARK;
zgu@9313 486 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, THREAD);
zgu@9313 487 if (has_init_error(THREAD)) {
zgu@9313 488 return;
zgu@9313 489 }
zgu@9313 490
duke@435 491 instanceKlassHandle klass (THREAD, k);
zgu@9313 492 instanceHandle thread_oop = klass->allocate_instance_handle(THREAD);
zgu@9313 493 if (has_init_error(THREAD)) {
zgu@9313 494 return;
zgu@9313 495 }
duke@435 496
duke@435 497 const char thread_name[] = "Attach Listener";
zgu@9313 498 Handle string = java_lang_String::create_from_str(thread_name, THREAD);
zgu@9313 499 if (has_init_error(THREAD)) {
zgu@9313 500 return;
zgu@9313 501 }
duke@435 502
duke@435 503 // Initialize thread_oop to put it into the system threadGroup
duke@435 504 Handle thread_group (THREAD, Universe::system_thread_group());
duke@435 505 JavaValue result(T_VOID);
duke@435 506 JavaCalls::call_special(&result, thread_oop,
duke@435 507 klass,
coleenp@2497 508 vmSymbols::object_initializer_name(),
coleenp@2497 509 vmSymbols::threadgroup_string_void_signature(),
duke@435 510 thread_group,
duke@435 511 string,
sla@5757 512 THREAD);
sla@5757 513
zgu@9313 514 if (has_init_error(THREAD)) {
sla@5757 515 return;
sla@5757 516 }
duke@435 517
never@1577 518 KlassHandle group(THREAD, SystemDictionary::ThreadGroup_klass());
duke@435 519 JavaCalls::call_special(&result,
duke@435 520 thread_group,
duke@435 521 group,
coleenp@2497 522 vmSymbols::add_method_name(),
coleenp@2497 523 vmSymbols::thread_void_signature(),
duke@435 524 thread_oop, // ARG 1
sla@5757 525 THREAD);
zgu@9313 526 if (has_init_error(THREAD)) {
sla@5757 527 return;
sla@5757 528 }
duke@435 529
duke@435 530 { MutexLocker mu(Threads_lock);
duke@435 531 JavaThread* listener_thread = new JavaThread(&attach_listener_thread_entry);
duke@435 532
duke@435 533 // Check that thread and osthread were created
duke@435 534 if (listener_thread == NULL || listener_thread->osthread() == NULL) {
duke@435 535 vm_exit_during_initialization("java.lang.OutOfMemoryError",
duke@435 536 "unable to create new native thread");
duke@435 537 }
duke@435 538
duke@435 539 java_lang_Thread::set_thread(thread_oop(), listener_thread);
duke@435 540 java_lang_Thread::set_daemon(thread_oop());
duke@435 541
duke@435 542 listener_thread->set_threadObj(thread_oop());
duke@435 543 Threads::add(listener_thread);
duke@435 544 Thread::start(listener_thread);
duke@435 545 }
duke@435 546 }
duke@435 547
duke@435 548 // Performs clean-up tasks on platforms where we can detect that the last
duke@435 549 // client has detached
duke@435 550 void AttachListener::detachall() {
duke@435 551 // call the platform dependent clean-up
duke@435 552 pd_detachall();
duke@435 553 }

mercurial