Bug 1550401 - Report OOM size when StringParam::GetString is failure. r=geckoview-reviewers,snorp a=jcristau
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Wed, 22 May 2019 18:43:08 +0000
changeset 533439 eeb4df23fecc835b765264d55032173c96e0db47
parent 533438 0221c97747ac3eebad8c9761a13c4d875c1ed45a
child 533440 09b6c96b16ca7a5f05c26a0560a678716a5cdaff
push id11322
push usermalexandru@mozilla.com
push dateTue, 28 May 2019 11:39:39 +0000
treeherdermozilla-beta@0a91cbfe3b3f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, snorp, jcristau
bugs1550401
milestone68.0
Bug 1550401 - Report OOM size when StringParam::GetString is failure. r=geckoview-reviewers,snorp a=jcristau Actually, all JNI Exceptions with `java.lang.OutOfMemoryError` call `NS_ABORT_OOM(0)`. But `JNIEnv::NewString` in `StringParam::GetString` can know OOM size when returning `nullptr`. So call `NS_ABORT_OOM` directly when `NewString` is failure. Differential Revision: https://phabricator.services.mozilla.com/D31026
widget/android/jni/Refs.h
--- a/widget/android/jni/Refs.h
+++ b/widget/android/jni/Refs.h
@@ -705,16 +705,19 @@ class StringParam : public String::Ref {
 
  private:
   // Not null if we should delete ref on destruction.
   JNIEnv* const mEnv;
 
   static jstring GetString(JNIEnv* env, const nsAString& str) {
     const jstring result = env->NewString(
         reinterpret_cast<const jchar*>(str.BeginReading()), str.Length());
+    if (!result) {
+      NS_ABORT_OOM(str.Length() * sizeof(char16_t));
+    }
     MOZ_CATCH_JNI_EXCEPTION(env);
     return result;
   }
 
  public:
   MOZ_IMPLICIT StringParam(decltype(nullptr)) : Ref(nullptr), mEnv(nullptr) {}
 
   MOZ_IMPLICIT StringParam(const Ref& ref) : Ref(ref.Get()), mEnv(nullptr) {}