diff options
| -rw-r--r-- | runtime/runtime.cc | 20 | ||||
| -rwxr-xr-x | test/004-ThreadStress/check | 7 |
2 files changed, 21 insertions, 6 deletions
diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 2f45b100d7..38c2bfd96f 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -291,11 +291,21 @@ Runtime::~Runtime() { const bool attach_shutdown_thread = self == nullptr; if (attach_shutdown_thread) { // We can only create a peer if the runtime is actually started. This is only not true during - // some tests. - CHECK(AttachCurrentThread("Shutdown thread", - false, - GetSystemThreadGroup(), - /* Create peer */IsStarted())); + // some tests. If there is extreme memory pressure the allocation of the thread peer can fail. + // In this case we will just try again without allocating a peer so that shutdown can continue. + // Very few things are actually capable of distinguishing between the peer & peerless states so + // this should be fine. + bool thread_attached = AttachCurrentThread("Shutdown thread", + /* as_daemon */ false, + GetSystemThreadGroup(), + /* Create peer */ IsStarted()); + if (UNLIKELY(!thread_attached)) { + LOG(WARNING) << "Failed to attach shutdown thread. Trying again without a peer."; + CHECK(AttachCurrentThread("Shutdown thread (no java peer)", + /* as_daemon */ false, + /* thread_group*/ nullptr, + /* Create peer */ false)); + } self = Thread::Current(); } else { LOG(WARNING) << "Current thread not detached in Runtime shutdown"; diff --git a/test/004-ThreadStress/check b/test/004-ThreadStress/check index 77e4cdbda0..ecc5ea8a37 100755 --- a/test/004-ThreadStress/check +++ b/test/004-ThreadStress/check @@ -15,4 +15,9 @@ # limitations under the License. # Do not compare numbers, so replace numbers with 'N'. -sed '-es/[0-9][0-9]*/N/g' "$2" | diff --strip-trailing-cr -q "$1" - >/dev/null
\ No newline at end of file +# Remove all messages relating to failing to allocate a java-peer for the +# shutdown thread. This can occasionally happen with this test but it is not +# something we really need to worry about here. +sed '-es/[0-9][0-9]*/N/g' "$2" \ + | sed "/Exception creating thread peer:/,+3d" \ + | diff --strip-trailing-cr -q "$1" - >/dev/null |