summaryrefslogtreecommitdiff
path: root/runtime/native/java_lang_Thread.cc
AgeCommit message (Collapse)Author
2021-09-04Improve suspension timeout diagnostic and fix raceHans Boehm
Fix a data race on state_and_flags. Since the access was volatile and there are system calls in the loop, this is extremely unlikey to have casused the bug here, but ... So, assuming this is still broken, produce more informative output once we time out. Remove unused argument from SuspendThreadByPeer(). It made the logic more complicated and made it harder to reason about correctness. Remove dead code after LOG(FATAL, ...) Bug: 181778559 Test: TreeHugger, temporarily paste log message into hotter path. Merged-In: I6f3455925b3a3f4726a870150aeb54ea60a38d67 (cherry picked from commit 9d27fbc8ced914f4726187920a7794b07eca3e71) Change-Id: Ia3f04153fb0a4f1b899fb0f68a6121728f89cb91 (cherry picked from commit 116203735734738cbfdffc2163b08b1707089f9c)
2020-10-02Revert "Add getNativeTid function"Rick Yiu
Revert submission 1202786-setpriority Reason for revert: will cause lock contention Reverted Changes: I46093c953:Use ThreadPrioritySetter to set thread priority Ic13c13803:Add getNativeTid function Ib486b7229:Implement the ThreadPrioritySetter interface Bug: 139521784 Test: build pass Change-Id: Ie13eee23321cf78cd8e0c4e06b5215936710d8d7
2020-01-17Add getNativeTid functionRick Yiu
Add a function to get native thread id for java Thread. Bug: 139521784 Test: CtsLibcoreTestCases, device boot to home, thread priority set as expected. Change-Id: Ic13c1380374044754f007136666dc0928ce1f143
2019-03-27Revert "Revert "Change state to waiting during aborting the VM""Koji Fukui
This reverts commit ebb481d070e3fdbb7950580e6f6886c3231a1ad9. Dex2oatWatchdogTest.TestWatchdogTrigger passed. Apply the change again. Test: ART_HEAP_POISONING=true make test-art-host-gtest-dex2oat_test64 Bug: 127875380 Change-Id: If4326990cd612815ffe1511490712ca8babfec55
2019-03-19Revert "Change state to waiting during aborting the VM"Nicolas Geoffray
This reverts commit 97b964960123d5f215a1cebbce548c8a5322c307. Bug: 127875380 Reason for revert: Broke Dex2oatWatchdogTest.TestWatchdogTrigger on host x86_64 and heap poisoning. Change-Id: Iaebfc4a03543bff4e7239d711dd7ad8c7f880d52
2019-03-18Change state to waiting during aborting the VMKoji Fukui
Symptom: Process freeze when multiple runtime error happen on runnable threads. Root cause: When multiple runtime error happen, only one thread locks abort_lock_ and other threads are blocked even if they are runnable state. If an other thread tries to suspend blocked threads at the same time, blocked threads can't be suspended until abort_lock_ is unlocked from owner thread. But owner thread can be suspended even if it locks abort_lock_. Thus, these threads causes dead lock. Solution: Change state to waiting when locking abort_lock_. Bug: 127875380 Change-Id: I7e914924690bb30d6d0490cf5f8afdb1c3cd4e4a
2018-10-23ART: Refactor for bugprone-argument-commentAndreas Gampe
Handles runtime. Bug: 116054210 Test: WITH_TIDY=1 mmma art Change-Id: Ibc0d5086809d647f0ce4df5452eb84442d27ecf0
2018-08-15Rename Thread native methods to match OpenJDK 8u121-b13Paul Duffin
Renames the following native methods: * nativeSetPriority -> setPriority0 * nativeSetName -> setNativeName * nativeInterrupt -> interrupt0 Tested using: make checkbuild, flash and CtsLibcoreTestCases art/test/testrunner/run_build_test_target.py -j80 art-test Bug: 80180276 Test: see above Change-Id: I83ac240dfc108a2bf7f6c33895c9046b74707072
2018-06-01ObjPtr<>-ify array allocations.Vladimir Marko
And remove some unnecessary calls to ObjPtr<>::Ptr(). Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 31113334 Change-Id: Ie313980f7f23b33b0ccea4fa8d5131d643c59080
2018-05-25Rename nativeHoldsLock to holdsLock and make it work on current threadPaul Duffin
The Java native method nativeHoldsLock has been renamed to match the upstream OpenJDK 8u121-b13 and changed from an instance method on Thread to a static method. This makes the corresponding change to the native implementation of that method. Test: make checkbuild, flash, CtsLibcoreTestCases Bug: 74379469 Change-Id: Ib9dedccd3014c01c148ff824764be319c2a7a123
2018-05-09ART: Move JNI files to runtime/jni/ .Vladimir Marko
Test: Rely on TreeHugger. Change-Id: I9cae11191ef1567ae9453be498882a7767285140
2017-12-22Extensions to check JNI.Ian Rogers
Ensure critical lock isn't held when returning from a down-call. Log a warning if the critical lock is held for a significant period of time. Refactor JNIEnvExt to be a class rather than a struct. Test: mma test-art-host Change-Id: I4d149cb04d3a7308a22b92b196e51e2f1ae17ede
2017-10-25ART: Depend on libnativehelper headers onlyAndreas Gampe
Depend on header-only versions where possible. Move projects excluding libart to libnativehelper_header_only. Bug: 65522645 Test: mmma art Change-Id: I53dd3b2a97e94ee685f72de007ed3858f7f5c6b6
2017-09-14Add support for JVMTI monitor events.Alex Light
Adds support for the JVMTI can_generate_monitor_events capability and all associated events. This adds support for the JVMTI_EVENT_MONITOR_WAIT, JVMTI_EVENT_MONITOR_WAITED, JVMTI_EVENT_MONITOR_CONTENDED_ENTER, and JVMTI_EVENT_MONITOR_CONTENDED_ENTERED events. Bug: 65558434 Bug: 62821960 Bug: 34415266 Test: ./test.py --host -j50 Change-Id: I0fe8038e6c4249e77d37a67e5056b5d2a94b6f48
2017-07-18art: use proper nativehelper headersSteven Moreland
libnativeheader exports headers under nativeheader. These were available before incorrectly as global headers in order to give access to jni.h. Test: modules using art find headers Bug: 63762847 Change-Id: I5c820d677e94e07b2859e78610bc997fe51b41dc
2017-07-13Add Jvmti Suspend/ResumeThread functionsAlex Light
Enable the can_suspend jvmti capability and implement all required functionality associated with it. Test: ./test.py --host -j40 Bug: 34415266 Bug: 62821960 Bug: 63579748 Change-Id: I83b92de7f81622e1658114b034918e8295805b6e
2017-06-30Add SuspendReason enum and change Suspension functions.Alex Light
More self-documenting and more type safe. Bug: 62821960 Test: ./test.py Change-Id: Ic7a1ae6a25e687d65f5aa10c1aad54a7b80dd086
2017-06-01ART: Move RegisterNatives helperAndreas Gampe
Move the helper closer to the users. Test: m test-art-host Change-Id: Id05ce5f60af54d0c5aef0c7d8932706c4602fc94
2017-05-30ART: More header cleanup - jni_internal.hAndreas Gampe
Move jni_macros.h to the clients (users of RegisterNativeMethods). Test: mmma art Change-Id: I052ac9f703ec69f0a2df1efcaf9f4a450eb7be1c
2017-02-21jni: Switch to @FastNative for all JNI functions. Deprecate !bang JNI.Igor Murashkin
Switches all (248) methods that previously used !bang JNI in art/libcore to all use @FastNative. Also deprecate !bang JNI since nothing in Android seems to (or should be) using it anymore. This measures to be a 3% startup time improvement in system_server. Test: make test-art-host Bug: 34955272 Change-Id: I0881f401c7660c79f275235362777bfa58241deb
2017-02-03ART: Refactor verify_object.hAndreas Gampe
Move the actual VerifyObject check into a new cc file, as we commonly don't enable the check at all. This allows to cut the -inl include from almost all current users. This also exposes missing -inl includes. Also fix up some of our old mess where .h defined functions require -inl.h defined functions. Test: m Change-Id: I3dd821bbe2015564a29bf1ed9be00f7a7276ad61
2016-10-04Rename ObjPtr::Decode to ObjPtr::PtrMathieu Chartier
Done to prevent ambiguity with ScopedObjectAccess::Decode. Bug: 31113334 Test: test-art-host Change-Id: I07a2497cc9cf66386311798933547471987fc316
2016-09-29Clean up ScopedThreadStateChange to use ObjPtrMathieu Chartier
Also fixed inclusion of -inl.h files in .h files by adding scoped_object_access-inl.h and scoped_fast_natvie_object_access-inl.h Changed AddLocalReference / Decode to use ObjPtr. Changed libartbenchmark to be debug to avoid linkage errors. Bug: 31113334 Test: test-art-host Change-Id: I4d2e160483a29d21e1e0e440585ed328b9811483
2016-04-12ART: Flag to fail thread creationAndreas Gampe
Add a flag to mark when the zygote is not allowed to create threads. Bug: 27248115 Bug: 28149511 Change-Id: I1dc3620d9e7d0054c672b993d89459fc4b353dfc
2015-12-21Treat thread state kWaitingWeakGcRootRead as kJavaRunnable.Hiroshi Yamauchi
Like kSuspended, kWaitingWeakGcRootRead means temporarily waiting for GC's purpose rather than the thread is waiting on a monitor. This may fix some jsr166 test failures. Bug: 25883050 Bug: 12687968 Change-Id: Ib53e18c0fb2ff95aa0491b1531201e583288684e
2015-08-27Synchronize JNI critical calls with the CC collector thread flip.Hiroshi Yamauchi
JNI critical calls (like GetArrayElementsCritical) would need to block for the whole GC run to finish if the CC collector GC is ongoing. This CL changes it so that they don't need to block for the GC run, but only for the duration of the thread flip operation, which is much shorter. This is valid due to the to-space invariant. Bug: 12687968 Bug: 19235243 Change-Id: I1b6b4ae4fa539ddc0ec50b10ae8c8709f2a12fe8
2015-08-17ART: Some header cleaning around bit-utilsAndreas Gampe
Try to remove dependencies where they are not necessary. Change-Id: I5ff35cb17aea369bed3725b1610b50d7eb05b81e
2015-08-04Address some comments and clean upMathieu Chartier
Change-Id: I538cf204f1c89d5fc81f8fc5e5800fcf1cf87359
2015-07-17Change intern table to not use WaitHoldingLocksMathieu Chartier
Bug: 22423014 Change-Id: I9e16b8cb4def72fff73f1783a182877105feb7aa
2015-05-12Hold heap bitmap lock in Heap::GetObjectsAllocatedMathieu Chartier
Fixes a race condition where add and remove space could cause a crash when we iterated over the spaces. TODO: Add a spaces lock or something to guard against this. (cherry picked from commit a395c0a492079d86b312c9edc796d63001576954) Bug: 21031927 Change-Id: I7f0d558316f8e9d9f22ffd182e8666355bf50d47
2015-04-22Replace NULL with nullptrMathieu Chartier
Also fixed some lines that were too long, and a few other minor details. Change-Id: I6efba5fb6e03eb5d0a300fddb2a75bf8e2f175cb
2015-03-10Remove ThrowLocation.Nicolas Geoffray
Note that this is a cleanup change, and has no functionality change. The ThrowLocation had no use anymore. Change-Id: I3d2126af1dc673cec3a0453ff3d56a172663a5f6
2015-01-20Clean up the locks around Heap::VisitObjects().Hiroshi Yamauchi
This is so that we could support suspending all threads when visiting objects in the presence of a concurrent, moving collector. Bug: 12687968 Change-Id: Icc8e60630465afde948ebc6ea91d4ebaff5d7837
2014-11-24ART: Fix unused variables and functionsAndreas Gampe
Change-Id: Icbab884d2dfd71656347368b424cb35cbf524051
2014-11-12Modify the behavior of thread suspend shootouts.Ian Rogers
The thread doing the suspension doesn't attempt to suspend the other thread unless it knows another thread isn't trying to suspend it. Use the suspend count, and its lock, for this purpose. Re-enable ThreadStress test. Bug: 15446488 Change-Id: Idd34410c7b89d8abd6973e5699a15ca699472c78
2014-11-04ART: More warningsAndreas Gampe
Enable -Wno-conversion-null, -Wredundant-decls and -Wshadow in general, and -Wunused-but-set-parameter for GCC builds. Change-Id: I81bbdd762213444673c65d85edae594a523836e5
2014-08-28Fix issue with Thread.setName hanging after Thread.startBrian Carlstrom
When suspending a thread by peer the invariant that only attached threads are suspended must be maintained. Add a ThreadList::Contains check which requires making this method non-static. Add some extra thread logging. Bug: 17302037 (cherry picked from commit 37c16453a92bbf1a47f042000318a1b60381017d) Change-Id: I51832785d4b4b431e035318e75635f442e89a1fb
2014-07-17Avoid race in single thread suspension.Ian Rogers
Don't allow more than one concurrent single thread suspension to avoid potential cycles and deadlocks where threads try to suspend each other. Bug: 16364458, 16354227 Change-Id: I907f1d5591a6aa5c241d37d6b4a34f968f98df77
2014-07-09Fix method tracing from command-lineSebastien Hertz
Transitions current thread to the new kWaitingForMethodTracingStart thread state when starting method tracing. Ensures there is a current thread when method tracing is stopped due to runtime shutdown. If the current thread has been detached, we now re-attach it. Note: we only do this if method tracing has been activated from command-line. Fixes instrumentation when forcing interpreter mode (-Xint) with method tracing enabled. Removes unused parameter from UnsafeLogFatalForThreadSuspendAllTimeout. Bug: https://code.google.com/p/android/issues/detail?id=72094 Bug: 11683397 Change-Id: I70f000fb46ddd95d6ad51ea0a8eee77697a045e9
2014-04-22Warn when thread state lookup fails.Ian Rogers
Change-Id: I06781caddcade26148921bc225f28db8b3a63a35
2014-04-01Allow mixing of thread offsets between 32 and 64bit architectures.Ian Rogers
Begin a more full implementation x86-64 REX prefixes. Doesn't implement 64bit thread offset support for the JNI compiler. Change-Id: If9af2f08a1833c21ddb4b4077f9b03add1a05147
2014-03-14Refactor reflective method invocation.Ian Rogers
Move invocation code out of JNI internal into reflection, including ArgArray code. Make reflective invocation use the ArgArray to build arguments rather than allocating a jvalue[] and unboxing arguments into that. Move reflection part of jni_internal_test into reflection_test. Make greater use of fast JNI. Change-Id: Ib381372df5f9a83679e30e7275de24fa0e6b1057
2014-02-21Fix and optimize verify object.Mathieu Chartier
VerifyObject no longer resides in heap. You can now enable VerifyObject for non-debug builds. VerifyStack is still slow, so it is now guarded by its own flag. Fixed the image writer to not use verification at places where verification fails due to invalid reads. Fixed RosAlloc to use SizeOf which doesn't call verify object. Added a flag paremeter to some of the mirror getters / setters to be able to selectively disable VerifyObject on certain calls. Optimized the GC to not verify each object multiple times during object scanning if verify object is enabled. Added 3 verification options: verify reads, verify this, and verify writes so that you can select how much verification you want for mirror getters and setters. Removed some useless DCHECKs which would slow debug builds without providing any benefits. TODO: RosAlloc verification doesn't currently work with verify objects. Bug: 12934910 Bug: 12879358 Change-Id: Ic61033104dfc334543f89b0fc0ad8cd4f4015d69
2014-01-13Selective deoptimization.Sebastien Hertz
Update the instrumentation to allow selective deoptimization. Separate instrumentation listener registration from stubs configuration. A listener is now responsible for configuring the appropriate stubs. - The method tracing listener installs instrumentation entry/exit stubs or the interpreter depending on the accuracy of events we want (controlled by kDeoptimizeForAccurateMethodEntryExitListeners). - The debugger registers itself as an instrumentation listener but does not modify methods entrypoints. It only does this on demand when deoptimizing one method or all the methods. The selective deoptimization is used for breakpoint only. When a breakpoint is requested, the debugger deoptimizes this method by setting its entrypoint to the interpreter stub. As several breakpoints can be set on the same method, we deoptimize only once. When the last breakpoint on a method is removed, we reoptimize it by restoring the original entrypoints. The full deoptimization is used for method entry, method exit and single-step events. When one of these events is requested, we force eveything to run with the interpreter (except native and proxy methods). When the last of these events is removed, we restore all methods entrypoints except those which are currently deoptimized. Deoptimizing a method requires all mutator threads be suspended in order to walk each thread's stack and ensure no code is actually executing while we modify methods entrypoints. Suspending all the threads requires to not hold any lock. In the debugger, we deoptimize/undeoptimize when the JDWP event list changes (add or remove a breakpoint for instance). During the update, we need to hold the JDWP event list lock. This means we cannot suspend all the threads at this time. In order to deal with these constraints, we support a queue of deoptimization requests. When an event needs selective/full deoptimization/undeoptimization, we save its request in the queue. Once we release the JDWP event list lock, we suspend all the threads, process this queue and finally resume all the threads. This is done in Dbg::ManageDeoptimization. Note: threads already suspended before doing this remain suspended so we don't "break" debugger suspensions. When we deoptimize one method or every method, we need to browse each thread's stack to install instrumentation exit PC as return PC and save information in the instrumentation stack frame. Now we can deoptimize multiple times during the execution of an application, we need to preserve exisiting instrumentation frames (which is the result of a previous deoptimization). This require to push new instrumentation frames before existing ones so we don't corrupt the instrumentation stack frame while walking the stack. Bug: 11538162 Change-Id: I477142df17edf2dab8ac5d879daacc5c08a67c39
2013-10-20Fast JNI support.Ian Rogers
Use a modifier to signal a native method is a fast JNI method. If the modifier is set then don't perform runnable transitions. Change-Id: I7835b4d837bfdd1cb8e2d54b919c0d5e6cf90499
2013-10-02Inflate contended lock word by suspending owner.Ian Rogers
Bug 6961405. Don't inflate monitors for Notify and NotifyAll. Tidy lock word, handle recursive lock case alongside unlocked case and move assembly out of line (except for ARM quick). Also handle null in out-of-line assembly as the test is quick and the enter/exit code is already a safepoint. To gain ownership of a monitor on behalf of another thread, monitor contenders must not hold the monitor_lock_, so they wait on a condition variable. Reduce size of per mutex contention log. Be consistent in calling thin lock thread ids just thread ids. Fix potential thread death races caused by the use of FindThreadByThreadId, make it invariant that returned threads are either self or suspended now. Code size reduction on ARM boot.oat 0.2%. Old nexus 7 speedup 0.25%, new nexus 7 speedup 1.4%, nexus 10 speedup 2.24%, nexus 4 speedup 2.09% on DeltaBlue. Change-Id: Id52558b914f160d9c8578fdd7fc8199a9598576a
2013-07-26Fix cpplint whitespace/comments issuesBrian Carlstrom
Change-Id: Iae286862c85fb8fd8901eae1204cd6d271d69496
2013-07-12Create separate Android.mk for main build targetsBrian Carlstrom
The runtime, compiler, dex2oat, and oatdump now are in seperate trees to prevent dependency creep. They can now be individually built without rebuilding the rest of the art projects. dalvikvm and jdwpspy were already this way. Builds in the art directory should behave as before, building everything including tests. Change-Id: Ic6b1151e5ed0f823c3dd301afd2b13eb2d8feb81