OSDN Git Service

Ensure that java.lang.reflect.Field is initialized
authorPrzemyslaw Szczepaniak <pszczepaniak@google.com>
Thu, 12 May 2016 13:55:48 +0000 (14:55 +0100)
committerPrzemyslaw Szczepaniak <pszczepaniak@google.com>
Fri, 13 May 2016 12:21:45 +0000 (13:21 +0100)
Recent change in libcore (a move of clinit code
to register function for java.net.InetAddress
class) was triggering a failure in 119-noimage-patchoat
test. Failure was occurring when the test was running
without the image. This was caused by the
java.lang.reflect.Field not being initialized when
running InetAddress.<clinit>, which is a side effect
of calling JNIEnv->GetMethodId inside the libcore JNI_OnLoad.

This changes makes sure that this class is initialized
when we're running without image.

Bug: 28153851
Change-Id: I8aeb5eb312a163c452c40b851112544a8340e488

runtime/runtime.cc

index 45ba7d0..ca8f8bb 100644 (file)
@@ -577,9 +577,14 @@ bool Runtime::Start() {
 
   if (!IsImageDex2OatEnabled() || !GetHeap()->HasBootImageSpace()) {
     ScopedObjectAccess soa(self);
-    StackHandleScope<1> hs(soa.Self());
-    auto klass(hs.NewHandle<mirror::Class>(mirror::Class::GetJavaLangClass()));
-    class_linker_->EnsureInitialized(soa.Self(), klass, true, true);
+    StackHandleScope<2> hs(soa.Self());
+
+    auto class_class(hs.NewHandle<mirror::Class>(mirror::Class::GetJavaLangClass()));
+    auto field_class(hs.NewHandle<mirror::Class>(mirror::Field::StaticClass()));
+
+    class_linker_->EnsureInitialized(soa.Self(), class_class, true, true);
+    // Field class is needed for register_java_net_InetAddress in libcore, b/28153851.
+    class_linker_->EnsureInitialized(soa.Self(), field_class, true, true);
   }
 
   // InitNativeMethods needs to be after started_ so that the classes