comparison src/share/vm/runtime/thread.cpp @ 4970:33df1aeaebbf

Merge with http://hg.openjdk.java.net/hsx/hsx24/hotspot/
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 27 Feb 2012 13:10:13 +0100
parents 723df37192d6 f1cb6f9cfe21
children 1b8d02e10ee8
comparison
equal deleted inserted replaced
4703:2cfb7fb2dce7 4970:33df1aeaebbf
1 /* 1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
34 #endif 34 #endif
35 #include "interpreter/interpreter.hpp" 35 #include "interpreter/interpreter.hpp"
36 #include "interpreter/linkResolver.hpp" 36 #include "interpreter/linkResolver.hpp"
37 #include "interpreter/oopMapCache.hpp" 37 #include "interpreter/oopMapCache.hpp"
38 #include "jvmtifiles/jvmtiEnv.hpp" 38 #include "jvmtifiles/jvmtiEnv.hpp"
39 #include "memory/gcLocker.inline.hpp"
39 #include "memory/oopFactory.hpp" 40 #include "memory/oopFactory.hpp"
40 #include "memory/universe.inline.hpp" 41 #include "memory/universe.inline.hpp"
41 #include "oops/instanceKlass.hpp" 42 #include "oops/instanceKlass.hpp"
42 #include "oops/objArrayOop.hpp" 43 #include "oops/objArrayOop.hpp"
43 #include "oops/oop.inline.hpp" 44 #include "oops/oop.inline.hpp"
74 #include "runtime/vmThread.hpp" 75 #include "runtime/vmThread.hpp"
75 #include "runtime/vm_operations.hpp" 76 #include "runtime/vm_operations.hpp"
76 #include "services/attachListener.hpp" 77 #include "services/attachListener.hpp"
77 #include "services/management.hpp" 78 #include "services/management.hpp"
78 #include "services/threadService.hpp" 79 #include "services/threadService.hpp"
80 #include "trace/traceEventTypes.hpp"
79 #include "utilities/defaultStream.hpp" 81 #include "utilities/defaultStream.hpp"
80 #include "utilities/dtrace.hpp" 82 #include "utilities/dtrace.hpp"
81 #include "utilities/events.hpp" 83 #include "utilities/events.hpp"
82 #include "utilities/preserveException.hpp" 84 #include "utilities/preserveException.hpp"
83 #ifdef TARGET_OS_FAMILY_linux 85 #ifdef TARGET_OS_FAMILY_linux
233 NOT_PRODUCT(_allow_safepoint_count = 0;) 235 NOT_PRODUCT(_allow_safepoint_count = 0;)
234 NOT_PRODUCT(_skip_gcalot = false;) 236 NOT_PRODUCT(_skip_gcalot = false;)
235 CHECK_UNHANDLED_OOPS_ONLY(_gc_locked_out_count = 0;) 237 CHECK_UNHANDLED_OOPS_ONLY(_gc_locked_out_count = 0;)
236 _jvmti_env_iteration_count = 0; 238 _jvmti_env_iteration_count = 0;
237 set_allocated_bytes(0); 239 set_allocated_bytes(0);
240 set_trace_buffer(NULL);
238 _vm_operation_started_count = 0; 241 _vm_operation_started_count = 0;
239 _vm_operation_completed_count = 0; 242 _vm_operation_completed_count = 0;
240 _current_pending_monitor = NULL; 243 _current_pending_monitor = NULL;
241 _current_pending_monitor_is_from_java = true; 244 _current_pending_monitor_is_from_java = true;
242 _current_waiting_monitor = NULL; 245 _current_waiting_monitor = NULL;
1517 1520
1518 if (JvmtiExport::should_post_thread_life()) { 1521 if (JvmtiExport::should_post_thread_life()) {
1519 JvmtiExport::post_thread_start(this); 1522 JvmtiExport::post_thread_start(this);
1520 } 1523 }
1521 1524
1525 EVENT_BEGIN(TraceEventThreadStart, event);
1526 EVENT_COMMIT(event,
1527 EVENT_SET(event, javalangthread, java_lang_Thread::thread_id(this->threadObj())));
1528
1522 // We call another function to do the rest so we are sure that the stack addresses used 1529 // We call another function to do the rest so we are sure that the stack addresses used
1523 // from there will be lower than the stack base just computed 1530 // from there will be lower than the stack base just computed
1524 thread_main_inner(); 1531 thread_main_inner();
1525 1532
1526 // Note, thread is no longer valid at this point! 1533 // Note, thread is no longer valid at this point!
1599 if (!destroy_vm || JDK_Version::is_jdk12x_version()) { 1606 if (!destroy_vm || JDK_Version::is_jdk12x_version()) {
1600 // JSR-166: change call from from ThreadGroup.uncaughtException to 1607 // JSR-166: change call from from ThreadGroup.uncaughtException to
1601 // java.lang.Thread.dispatchUncaughtException 1608 // java.lang.Thread.dispatchUncaughtException
1602 if (uncaught_exception.not_null()) { 1609 if (uncaught_exception.not_null()) {
1603 Handle group(this, java_lang_Thread::threadGroup(threadObj())); 1610 Handle group(this, java_lang_Thread::threadGroup(threadObj()));
1604 Events::log("uncaught exception INTPTR_FORMAT " " INTPTR_FORMAT " " INTPTR_FORMAT",
1605 (address)uncaught_exception(), (address)threadObj(), (address)group());
1606 { 1611 {
1607 EXCEPTION_MARK; 1612 EXCEPTION_MARK;
1608 // Check if the method Thread.dispatchUncaughtException() exists. If so 1613 // Check if the method Thread.dispatchUncaughtException() exists. If so
1609 // call it. Otherwise we have an older library without the JSR-166 changes, 1614 // call it. Otherwise we have an older library without the JSR-166 changes,
1610 // so call ThreadGroup.uncaughtException() 1615 // so call ThreadGroup.uncaughtException()
1646 CLEAR_PENDING_EXCEPTION; 1651 CLEAR_PENDING_EXCEPTION;
1647 } 1652 }
1648 } 1653 }
1649 } 1654 }
1650 1655
1656 // Called before the java thread exit since we want to read info
1657 // from java_lang_Thread object
1658 EVENT_BEGIN(TraceEventThreadEnd, event);
1659 EVENT_COMMIT(event,
1660 EVENT_SET(event, javalangthread, java_lang_Thread::thread_id(this->threadObj())));
1661
1662 // Call after last event on thread
1663 EVENT_THREAD_EXIT(this);
1664
1651 // Call Thread.exit(). We try 3 times in case we got another Thread.stop during 1665 // Call Thread.exit(). We try 3 times in case we got another Thread.stop during
1652 // the execution of the method. If that is not enough, then we don't really care. Thread.stop 1666 // the execution of the method. If that is not enough, then we don't really care. Thread.stop
1653 // is deprecated anyhow. 1667 // is deprecated anyhow.
1654 { int count = 3; 1668 { int count = 3;
1655 while (java_lang_Thread::threadGroup(threadObj()) != NULL && (count-- > 0)) { 1669 while (java_lang_Thread::threadGroup(threadObj()) != NULL && (count-- > 0)) {
2272 // access error since that may block. 2286 // access error since that may block.
2273 thread->check_and_handle_async_exceptions(false); 2287 thread->check_and_handle_async_exceptions(false);
2274 } 2288 }
2275 } 2289 }
2276 2290
2291 // This is a variant of the normal
2292 // check_special_condition_for_native_trans with slightly different
2293 // semantics for use by critical native wrappers. It does all the
2294 // normal checks but also performs the transition back into
2295 // thread_in_Java state. This is required so that critical natives
2296 // can potentially block and perform a GC if they are the last thread
2297 // exiting the GC_locker.
2298 void JavaThread::check_special_condition_for_native_trans_and_transition(JavaThread *thread) {
2299 check_special_condition_for_native_trans(thread);
2300
2301 // Finish the transition
2302 thread->set_thread_state(_thread_in_Java);
2303
2304 if (thread->do_critical_native_unlock()) {
2305 ThreadInVMfromJavaNoAsyncException tiv(thread);
2306 GC_locker::unlock_critical(thread);
2307 thread->clear_critical_native_unlock();
2308 }
2309 }
2310
2277 // We need to guarantee the Threads_lock here, since resumes are not 2311 // We need to guarantee the Threads_lock here, since resumes are not
2278 // allowed during safepoint synchronization 2312 // allowed during safepoint synchronization
2279 // Can only resume from an external suspension 2313 // Can only resume from an external suspension
2280 void JavaThread::java_resume() { 2314 void JavaThread::java_resume() {
2281 assert_locked_or_safepoint(Threads_lock); 2315 assert_locked_or_safepoint(Threads_lock);
3332 initialize_class(vmSymbols::java_lang_ClassCastException(), CHECK_0); 3366 initialize_class(vmSymbols::java_lang_ClassCastException(), CHECK_0);
3333 initialize_class(vmSymbols::java_lang_ArrayStoreException(), CHECK_0); 3367 initialize_class(vmSymbols::java_lang_ArrayStoreException(), CHECK_0);
3334 initialize_class(vmSymbols::java_lang_ArithmeticException(), CHECK_0); 3368 initialize_class(vmSymbols::java_lang_ArithmeticException(), CHECK_0);
3335 initialize_class(vmSymbols::java_lang_StackOverflowError(), CHECK_0); 3369 initialize_class(vmSymbols::java_lang_StackOverflowError(), CHECK_0);
3336 initialize_class(vmSymbols::java_lang_IllegalMonitorStateException(), CHECK_0); 3370 initialize_class(vmSymbols::java_lang_IllegalMonitorStateException(), CHECK_0);
3371 initialize_class(vmSymbols::java_lang_IllegalArgumentException(), CHECK_0);
3337 } else { 3372 } else {
3338 warning("java.lang.OutOfMemoryError has not been initialized"); 3373 warning("java.lang.OutOfMemoryError has not been initialized");
3339 warning("java.lang.NullPointerException has not been initialized"); 3374 warning("java.lang.NullPointerException has not been initialized");
3340 warning("java.lang.ClassCastException has not been initialized"); 3375 warning("java.lang.ClassCastException has not been initialized");
3341 warning("java.lang.ArrayStoreException has not been initialized"); 3376 warning("java.lang.ArrayStoreException has not been initialized");
3342 warning("java.lang.ArithmeticException has not been initialized"); 3377 warning("java.lang.ArithmeticException has not been initialized");
3343 warning("java.lang.StackOverflowError has not been initialized"); 3378 warning("java.lang.StackOverflowError has not been initialized");
3379 warning("java.lang.IllegalArgumentException has not been initialized");
3344 } 3380 }
3345 } 3381 }
3346 3382
3347 // See : bugid 4211085. 3383 // See : bugid 4211085.
3348 // Background : the static initializer of java.lang.Compiler tries to read 3384 // Background : the static initializer of java.lang.Compiler tries to read
3368 // This should also be taken out as soon as 4211383 gets fixed. 3404 // This should also be taken out as soon as 4211383 gets fixed.
3369 reset_vm_info_property(CHECK_0); 3405 reset_vm_info_property(CHECK_0);
3370 3406
3371 quicken_jni_functions(); 3407 quicken_jni_functions();
3372 3408
3409 // Must be run after init_ft which initializes ft_enabled
3410 if (TRACE_INITIALIZE() != JNI_OK) {
3411 vm_exit_during_initialization("Failed to initialize tracing backend");
3412 }
3413
3373 // Set flag that basic initialization has completed. Used by exceptions and various 3414 // Set flag that basic initialization has completed. Used by exceptions and various
3374 // debug stuff, that does not work until all basic classes have been initialized. 3415 // debug stuff, that does not work until all basic classes have been initialized.
3375 set_init_completed(); 3416 set_init_completed();
3376 3417
3377 #ifndef USDT2 3418 #ifndef USDT2
3426 // Launch -Xrun agents 3467 // Launch -Xrun agents
3427 // Must be done in the JVMTI live phase so that for backward compatibility the JDWP 3468 // Must be done in the JVMTI live phase so that for backward compatibility the JDWP
3428 // back-end can launch with -Xdebug -Xrunjdwp. 3469 // back-end can launch with -Xdebug -Xrunjdwp.
3429 if (!EagerXrunInit && Arguments::init_libraries_at_startup()) { 3470 if (!EagerXrunInit && Arguments::init_libraries_at_startup()) {
3430 create_vm_init_libraries(); 3471 create_vm_init_libraries();
3472 }
3473
3474 if (!TRACE_START()) {
3475 vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION));
3431 } 3476 }
3432 3477
3433 // Notify JVMTI agents that VM initialization is complete - nop if no agents. 3478 // Notify JVMTI agents that VM initialization is complete - nop if no agents.
3434 JvmtiExport::post_vm_initialized(); 3479 JvmtiExport::post_vm_initialized();
3435 3480
3866 } 3911 }
3867 3912
3868 ThreadService::add_thread(p, daemon); 3913 ThreadService::add_thread(p, daemon);
3869 3914
3870 // Possible GC point. 3915 // Possible GC point.
3871 Events::log("Thread added: " INTPTR_FORMAT, p); 3916 Events::log(p, "Thread added: " INTPTR_FORMAT, p);
3872 } 3917 }
3873 3918
3874 void Threads::remove(JavaThread* p) { 3919 void Threads::remove(JavaThread* p) {
3875 // Extra scope needed for Thread_lock, so we can check 3920 // Extra scope needed for Thread_lock, so we can check
3876 // that we do not remove thread without safepoint code notice 3921 // that we do not remove thread without safepoint code notice
3911 // of this thread since it is removed from the queue. 3956 // of this thread since it is removed from the queue.
3912 p->set_terminated_value(); 3957 p->set_terminated_value();
3913 } // unlock Threads_lock 3958 } // unlock Threads_lock
3914 3959
3915 // Since Events::log uses a lock, we grab it outside the Threads_lock 3960 // Since Events::log uses a lock, we grab it outside the Threads_lock
3916 Events::log("Thread exited: " INTPTR_FORMAT, p); 3961 Events::log(p, "Thread exited: " INTPTR_FORMAT, p);
3917 } 3962 }
3918 3963
3919 // Threads_lock must be held when this is called (or must be called during a safepoint) 3964 // Threads_lock must be held when this is called (or must be called during a safepoint)
3920 bool Threads::includes(JavaThread* p) { 3965 bool Threads::includes(JavaThread* p) {
3921 assert(Threads_lock->is_locked(), "sanity check"); 3966 assert(Threads_lock->is_locked(), "sanity check");