Mercurial > hg > graal-jvmci-8
comparison src/share/vm/runtime/thread.cpp @ 8124:5fc51c1ecdeb
Merge.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 05 Mar 2013 23:44:54 +0100 |
parents | c6c72de0537e b8d5d7a6c94c |
children | b8f261ba79c6 |
comparison
equal
deleted
inserted
replaced
7943:a413bcd552a4 | 8124:5fc51c1ecdeb |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2013, 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. |
83 #include "trace/traceEventTypes.hpp" | 83 #include "trace/traceEventTypes.hpp" |
84 #include "utilities/defaultStream.hpp" | 84 #include "utilities/defaultStream.hpp" |
85 #include "utilities/dtrace.hpp" | 85 #include "utilities/dtrace.hpp" |
86 #include "utilities/events.hpp" | 86 #include "utilities/events.hpp" |
87 #include "utilities/preserveException.hpp" | 87 #include "utilities/preserveException.hpp" |
88 #include "utilities/macros.hpp" | |
88 #ifdef TARGET_OS_FAMILY_linux | 89 #ifdef TARGET_OS_FAMILY_linux |
89 # include "os_linux.inline.hpp" | 90 # include "os_linux.inline.hpp" |
90 #endif | 91 #endif |
91 #ifdef TARGET_OS_FAMILY_solaris | 92 #ifdef TARGET_OS_FAMILY_solaris |
92 # include "os_solaris.inline.hpp" | 93 # include "os_solaris.inline.hpp" |
95 # include "os_windows.inline.hpp" | 96 # include "os_windows.inline.hpp" |
96 #endif | 97 #endif |
97 #ifdef TARGET_OS_FAMILY_bsd | 98 #ifdef TARGET_OS_FAMILY_bsd |
98 # include "os_bsd.inline.hpp" | 99 # include "os_bsd.inline.hpp" |
99 #endif | 100 #endif |
100 #ifndef SERIALGC | 101 #if INCLUDE_ALL_GCS |
101 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp" | 102 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp" |
102 #include "gc_implementation/g1/concurrentMarkThread.inline.hpp" | 103 #include "gc_implementation/g1/concurrentMarkThread.inline.hpp" |
103 #include "gc_implementation/parallelScavenge/pcTasks.hpp" | 104 #include "gc_implementation/parallelScavenge/pcTasks.hpp" |
104 #endif | 105 #endif // INCLUDE_ALL_GCS |
105 #ifdef COMPILER1 | 106 #ifdef COMPILER1 |
106 #include "c1/c1_Compiler.hpp" | 107 #include "c1/c1_Compiler.hpp" |
107 #endif | 108 #endif |
108 #ifdef COMPILER2 | 109 #ifdef COMPILER2 |
109 #include "opto/c2compiler.hpp" | 110 #include "opto/c2compiler.hpp" |
1493 _popframe_preserved_args_size = 0; | 1494 _popframe_preserved_args_size = 0; |
1494 | 1495 |
1495 pd_initialize(); | 1496 pd_initialize(); |
1496 } | 1497 } |
1497 | 1498 |
1498 #ifndef SERIALGC | 1499 #if INCLUDE_ALL_GCS |
1499 SATBMarkQueueSet JavaThread::_satb_mark_queue_set; | 1500 SATBMarkQueueSet JavaThread::_satb_mark_queue_set; |
1500 DirtyCardQueueSet JavaThread::_dirty_card_queue_set; | 1501 DirtyCardQueueSet JavaThread::_dirty_card_queue_set; |
1501 #endif // !SERIALGC | 1502 #endif // INCLUDE_ALL_GCS |
1502 | 1503 |
1503 JavaThread::JavaThread(bool is_attaching_via_jni) : | 1504 JavaThread::JavaThread(bool is_attaching_via_jni) : |
1504 Thread() | 1505 Thread() |
1505 #ifndef SERIALGC | 1506 #if INCLUDE_ALL_GCS |
1506 , _satb_mark_queue(&_satb_mark_queue_set), | 1507 , _satb_mark_queue(&_satb_mark_queue_set), |
1507 _dirty_card_queue(&_dirty_card_queue_set) | 1508 _dirty_card_queue(&_dirty_card_queue_set) |
1508 #endif // !SERIALGC | 1509 #endif // INCLUDE_ALL_GCS |
1509 { | 1510 { |
1510 initialize(); | 1511 initialize(); |
1511 if (is_attaching_via_jni) { | 1512 if (is_attaching_via_jni) { |
1512 _jni_attach_state = _attaching_via_jni; | 1513 _jni_attach_state = _attaching_via_jni; |
1513 } else { | 1514 } else { |
1514 _jni_attach_state = _not_attaching_via_jni; | 1515 _jni_attach_state = _not_attaching_via_jni; |
1515 } | 1516 } |
1516 assert(_deferred_card_mark.is_empty(), "Default MemRegion ctor"); | 1517 assert(deferred_card_mark().is_empty(), "Default MemRegion ctor"); |
1517 _safepoint_visible = false; | 1518 _safepoint_visible = false; |
1518 } | 1519 } |
1519 | 1520 |
1520 bool JavaThread::reguard_stack(address cur_sp) { | 1521 bool JavaThread::reguard_stack(address cur_sp) { |
1521 if (_stack_guard_state != stack_guard_yellow_disabled) { | 1522 if (_stack_guard_state != stack_guard_yellow_disabled) { |
1558 // Remove this ifdef when C1 is ported to the compiler interface. | 1559 // Remove this ifdef when C1 is ported to the compiler interface. |
1559 static void compiler_thread_entry(JavaThread* thread, TRAPS); | 1560 static void compiler_thread_entry(JavaThread* thread, TRAPS); |
1560 | 1561 |
1561 JavaThread::JavaThread(ThreadFunction entry_point, size_t stack_sz) : | 1562 JavaThread::JavaThread(ThreadFunction entry_point, size_t stack_sz) : |
1562 Thread() | 1563 Thread() |
1563 #ifndef SERIALGC | 1564 #if INCLUDE_ALL_GCS |
1564 , _satb_mark_queue(&_satb_mark_queue_set), | 1565 , _satb_mark_queue(&_satb_mark_queue_set), |
1565 _dirty_card_queue(&_dirty_card_queue_set) | 1566 _dirty_card_queue(&_dirty_card_queue_set) |
1566 #endif // !SERIALGC | 1567 #endif // INCLUDE_ALL_GCS |
1567 { | 1568 { |
1568 if (TraceThreadEvents) { | 1569 if (TraceThreadEvents) { |
1569 tty->print_cr("creating thread %p", this); | 1570 tty->print_cr("creating thread %p", this); |
1570 } | 1571 } |
1571 initialize(); | 1572 initialize(); |
1907 | 1908 |
1908 if (JvmtiEnv::environments_might_exist()) { | 1909 if (JvmtiEnv::environments_might_exist()) { |
1909 JvmtiExport::cleanup_thread(this); | 1910 JvmtiExport::cleanup_thread(this); |
1910 } | 1911 } |
1911 | 1912 |
1912 #ifndef SERIALGC | 1913 // We must flush any deferred card marks before removing a thread from |
1913 // We must flush G1-related buffers before removing a thread from | |
1914 // the list of active threads. | 1914 // the list of active threads. |
1915 Universe::heap()->flush_deferred_store_barrier(this); | |
1916 assert(deferred_card_mark().is_empty(), "Should have been flushed"); | |
1917 | |
1918 #if INCLUDE_ALL_GCS | |
1919 // We must flush the G1-related buffers before removing a thread | |
1920 // from the list of active threads. We must do this after any deferred | |
1921 // card marks have been flushed (above) so that any entries that are | |
1922 // added to the thread's dirty card queue as a result are not lost. | |
1915 if (UseG1GC) { | 1923 if (UseG1GC) { |
1916 flush_barrier_queues(); | 1924 flush_barrier_queues(); |
1917 } | 1925 } |
1918 #endif | 1926 #endif // INCLUDE_ALL_GCS |
1919 | 1927 |
1920 // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread | 1928 // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread |
1921 Threads::remove(this); | 1929 Threads::remove(this); |
1922 } | 1930 } |
1923 | 1931 |
1924 #ifndef SERIALGC | 1932 #if INCLUDE_ALL_GCS |
1925 // Flush G1-related queues. | 1933 // Flush G1-related queues. |
1926 void JavaThread::flush_barrier_queues() { | 1934 void JavaThread::flush_barrier_queues() { |
1927 satb_mark_queue().flush(); | 1935 satb_mark_queue().flush(); |
1928 dirty_card_queue().flush(); | 1936 dirty_card_queue().flush(); |
1929 } | 1937 } |
1947 DirtyCardQueue& dirty_queue = dirty_card_queue(); | 1955 DirtyCardQueue& dirty_queue = dirty_card_queue(); |
1948 // The dirty card queue should have been constructed with its | 1956 // The dirty card queue should have been constructed with its |
1949 // active field set to true. | 1957 // active field set to true. |
1950 assert(dirty_queue.is_active(), "dirty card queue should be active"); | 1958 assert(dirty_queue.is_active(), "dirty card queue should be active"); |
1951 } | 1959 } |
1952 #endif // !SERIALGC | 1960 #endif // INCLUDE_ALL_GCS |
1953 | 1961 |
1954 void JavaThread::cleanup_failed_attach_current_thread() { | 1962 void JavaThread::cleanup_failed_attach_current_thread() { |
1955 if (get_thread_profiler() != NULL) { | 1963 if (get_thread_profiler() != NULL) { |
1956 get_thread_profiler()->disengage(); | 1964 get_thread_profiler()->disengage(); |
1957 ResourceMark rm; | 1965 ResourceMark rm; |
1975 | 1983 |
1976 if (UseTLAB) { | 1984 if (UseTLAB) { |
1977 tlab().make_parsable(true); // retire TLAB, if any | 1985 tlab().make_parsable(true); // retire TLAB, if any |
1978 } | 1986 } |
1979 | 1987 |
1980 #ifndef SERIALGC | 1988 #if INCLUDE_ALL_GCS |
1981 if (UseG1GC) { | 1989 if (UseG1GC) { |
1982 flush_barrier_queues(); | 1990 flush_barrier_queues(); |
1983 } | 1991 } |
1984 #endif | 1992 #endif // INCLUDE_ALL_GCS |
1985 | 1993 |
1986 Threads::remove(this); | 1994 Threads::remove(this); |
1987 delete this; | 1995 delete this; |
1988 } | 1996 } |
1989 | 1997 |
3607 SystemDictionary::compute_java_system_loader(THREAD); | 3615 SystemDictionary::compute_java_system_loader(THREAD); |
3608 if (HAS_PENDING_EXCEPTION) { | 3616 if (HAS_PENDING_EXCEPTION) { |
3609 vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION)); | 3617 vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION)); |
3610 } | 3618 } |
3611 | 3619 |
3612 #ifndef SERIALGC | 3620 #if INCLUDE_ALL_GCS |
3613 // Support for ConcurrentMarkSweep. This should be cleaned up | 3621 // Support for ConcurrentMarkSweep. This should be cleaned up |
3614 // and better encapsulated. The ugly nested if test would go away | 3622 // and better encapsulated. The ugly nested if test would go away |
3615 // once things are properly refactored. XXX YSR | 3623 // once things are properly refactored. XXX YSR |
3616 if (UseConcMarkSweepGC || UseG1GC) { | 3624 if (UseConcMarkSweepGC || UseG1GC) { |
3617 if (UseConcMarkSweepGC) { | 3625 if (UseConcMarkSweepGC) { |
3621 } | 3629 } |
3622 if (HAS_PENDING_EXCEPTION) { | 3630 if (HAS_PENDING_EXCEPTION) { |
3623 vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION)); | 3631 vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION)); |
3624 } | 3632 } |
3625 } | 3633 } |
3626 #endif // SERIALGC | 3634 #endif // INCLUDE_ALL_GCS |
3627 | 3635 |
3628 // Always call even when there are not JVMTI environments yet, since environments | 3636 // Always call even when there are not JVMTI environments yet, since environments |
3629 // may be attached late and JVMTI must track phases of VM execution | 3637 // may be attached late and JVMTI must track phases of VM execution |
3630 JvmtiExport::enter_live_phase(); | 3638 JvmtiExport::enter_live_phase(); |
3631 | 3639 |
3746 // Try to load the agent from the standard dll directory | 3754 // Try to load the agent from the standard dll directory |
3747 if (os::dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), | 3755 if (os::dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), |
3748 name)) { | 3756 name)) { |
3749 library = os::dll_load(buffer, ebuf, sizeof ebuf); | 3757 library = os::dll_load(buffer, ebuf, sizeof ebuf); |
3750 } | 3758 } |
3751 #ifdef KERNEL | |
3752 // Download instrument dll | |
3753 if (library == NULL && strcmp(name, "instrument") == 0) { | |
3754 char *props = Arguments::get_kernel_properties(); | |
3755 char *home = Arguments::get_java_home(); | |
3756 const char *fmt = "%s/bin/java %s -Dkernel.background.download=false" | |
3757 " sun.jkernel.DownloadManager -download client_jvm"; | |
3758 size_t length = strlen(props) + strlen(home) + strlen(fmt) + 1; | |
3759 char *cmd = NEW_C_HEAP_ARRAY(char, length, mtThread); | |
3760 jio_snprintf(cmd, length, fmt, home, props); | |
3761 int status = os::fork_and_exec(cmd); | |
3762 FreeHeap(props); | |
3763 if (status == -1) { | |
3764 warning(cmd); | |
3765 vm_exit_during_initialization("fork_and_exec failed: %s", | |
3766 strerror(errno)); | |
3767 } | |
3768 FREE_C_HEAP_ARRAY(char, cmd, mtThread); | |
3769 // when this comes back the instrument.dll should be where it belongs. | |
3770 library = os::dll_load(buffer, ebuf, sizeof ebuf); | |
3771 } | |
3772 #endif // KERNEL | |
3773 if (library == NULL) { // Try the local directory | 3759 if (library == NULL) { // Try the local directory |
3774 char ns[1] = {0}; | 3760 char ns[1] = {0}; |
3775 if (os::dll_build_name(buffer, sizeof(buffer), ns, name)) { | 3761 if (os::dll_build_name(buffer, sizeof(buffer), ns, name)) { |
3776 library = os::dll_load(buffer, ebuf, sizeof ebuf); | 3762 library = os::dll_load(buffer, ebuf, sizeof ebuf); |
3777 } | 3763 } |
4216 if (vmt->claim_oops_do(is_par, cp)) { | 4202 if (vmt->claim_oops_do(is_par, cp)) { |
4217 vmt->oops_do(f, cld_f, cf); | 4203 vmt->oops_do(f, cld_f, cf); |
4218 } | 4204 } |
4219 } | 4205 } |
4220 | 4206 |
4221 #ifndef SERIALGC | 4207 #if INCLUDE_ALL_GCS |
4222 // Used by ParallelScavenge | 4208 // Used by ParallelScavenge |
4223 void Threads::create_thread_roots_tasks(GCTaskQueue* q) { | 4209 void Threads::create_thread_roots_tasks(GCTaskQueue* q) { |
4224 ALL_JAVA_THREADS(p) { | 4210 ALL_JAVA_THREADS(p) { |
4225 q->enqueue(new ThreadRootsTask(p)); | 4211 q->enqueue(new ThreadRootsTask(p)); |
4226 } | 4212 } |
4232 ALL_JAVA_THREADS(p) { | 4218 ALL_JAVA_THREADS(p) { |
4233 q->enqueue(new ThreadRootsMarkingTask(p)); | 4219 q->enqueue(new ThreadRootsMarkingTask(p)); |
4234 } | 4220 } |
4235 q->enqueue(new ThreadRootsMarkingTask(VMThread::vm_thread())); | 4221 q->enqueue(new ThreadRootsMarkingTask(VMThread::vm_thread())); |
4236 } | 4222 } |
4237 #endif // SERIALGC | 4223 #endif // INCLUDE_ALL_GCS |
4238 | 4224 |
4239 void Threads::nmethods_do(CodeBlobClosure* cf) { | 4225 void Threads::nmethods_do(CodeBlobClosure* cf) { |
4240 ALL_JAVA_THREADS(p) { | 4226 ALL_JAVA_THREADS(p) { |
4241 p->nmethods_do(cf); | 4227 p->nmethods_do(cf); |
4242 } | 4228 } |
4340 Abstract_VM_Version::vm_release(), | 4326 Abstract_VM_Version::vm_release(), |
4341 Abstract_VM_Version::vm_info_string() | 4327 Abstract_VM_Version::vm_info_string() |
4342 ); | 4328 ); |
4343 st->cr(); | 4329 st->cr(); |
4344 | 4330 |
4345 #ifndef SERIALGC | 4331 #if INCLUDE_ALL_GCS |
4346 // Dump concurrent locks | 4332 // Dump concurrent locks |
4347 ConcurrentLocksDump concurrent_locks; | 4333 ConcurrentLocksDump concurrent_locks; |
4348 if (print_concurrent_locks) { | 4334 if (print_concurrent_locks) { |
4349 concurrent_locks.dump_at_safepoint(); | 4335 concurrent_locks.dump_at_safepoint(); |
4350 } | 4336 } |
4351 #endif // SERIALGC | 4337 #endif // INCLUDE_ALL_GCS |
4352 | 4338 |
4353 ALL_JAVA_THREADS(p) { | 4339 ALL_JAVA_THREADS(p) { |
4354 ResourceMark rm; | 4340 ResourceMark rm; |
4355 p->print_on(st); | 4341 p->print_on(st); |
4356 if (print_stacks) { | 4342 if (print_stacks) { |
4359 } else { | 4345 } else { |
4360 p->print_stack_on(st); | 4346 p->print_stack_on(st); |
4361 } | 4347 } |
4362 } | 4348 } |
4363 st->cr(); | 4349 st->cr(); |
4364 #ifndef SERIALGC | 4350 #if INCLUDE_ALL_GCS |
4365 if (print_concurrent_locks) { | 4351 if (print_concurrent_locks) { |
4366 concurrent_locks.print_locks_on(p, st); | 4352 concurrent_locks.print_locks_on(p, st); |
4367 } | 4353 } |
4368 #endif // SERIALGC | 4354 #endif // INCLUDE_ALL_GCS |
4369 } | 4355 } |
4370 | 4356 |
4371 VMThread::vm_thread()->print_on(st); | 4357 VMThread::vm_thread()->print_on(st); |
4372 st->cr(); | 4358 st->cr(); |
4373 Universe::heap()->print_gc_threads_on(st); | 4359 Universe::heap()->print_gc_threads_on(st); |