OSDN Git Service

Prevent stubs from being installed in java.lang.reflect.Proxy.<init>.
authorJeff Hao <jeffhao@google.com>
Fri, 15 Aug 2014 00:18:52 +0000 (17:18 -0700)
committerJeff Hao <jeffhao@google.com>
Fri, 15 Aug 2014 17:03:47 +0000 (17:03 +0000)
This CL is a better fix for proxy tracing and undoes the changes in
https://android-review.googlesource.com/#/c/103025/

Bug: 16386215

(cherry picked from commit db8a664e0b68c7c4d36270cd21dce8de1912d7f9)

Change-Id: Ic9e0ea2af7cb2da5d90c56aa009de92dba14cc47

build/Android.gtest.mk
runtime/class_linker.cc
runtime/common_runtime_test.cc
runtime/common_runtime_test.h
runtime/instrumentation.cc
runtime/proxy_test.cc

index 17c478c..9ee3b69 100644 (file)
@@ -114,7 +114,6 @@ RUNTIME_GTEST_COMMON_SRC_FILES := \
   runtime/monitor_pool_test.cc \
   runtime/monitor_test.cc \
   runtime/parsed_options_test.cc \
-  runtime/proxy_test.cc \
   runtime/reference_table_test.cc \
   runtime/thread_pool_test.cc \
   runtime/transaction_test.cc \
@@ -125,6 +124,7 @@ RUNTIME_GTEST_COMMON_SRC_FILES := \
 
 COMPILER_GTEST_COMMON_SRC_FILES := \
   runtime/jni_internal_test.cc \
+  runtime/proxy_test.cc \
   runtime/reflection_test.cc \
   compiler/dex/global_value_numbering_test.cc \
   compiler/dex/local_value_numbering_test.cc \
index df41c96..0e086e2 100644 (file)
@@ -3519,19 +3519,13 @@ mirror::ArtMethod* ClassLinker::CreateProxyConstructor(Thread* self,
       proxy_class->GetDirectMethods();
   CHECK_EQ(proxy_direct_methods->GetLength(), 16);
   mirror::ArtMethod* proxy_constructor = proxy_direct_methods->Get(2);
+  // Clone the existing constructor of Proxy (our constructor would just invoke it so steal its
+  // code_ too)
   mirror::ArtMethod* constructor = down_cast<mirror::ArtMethod*>(proxy_constructor->Clone(self));
   if (constructor == nullptr) {
     CHECK(self->IsExceptionPending());  // OOME.
     return nullptr;
   }
-  // Make the proxy constructor's code always point to the uninstrumented code. This avoids
-  // getting a method enter event for the proxy constructor as the proxy constructor doesn't
-  // have an activation.
-  bool have_portable_code;
-  constructor->SetEntryPointFromQuickCompiledCode(GetQuickOatCodeFor(proxy_constructor));
-  constructor->SetEntryPointFromPortableCompiledCode(GetPortableOatCodeFor(proxy_constructor,
-                                                                           &have_portable_code));
-
   // Make this constructor public and fix the class to be our Proxy version
   constructor->SetAccessFlags((constructor->GetAccessFlags() & ~kAccProtected) | kAccPublic);
   constructor->SetDeclaringClass(klass.Get());
index 6f3b3a3..989384e 100644 (file)
@@ -285,19 +285,6 @@ std::string CommonRuntimeTest::GetDexFileName(const std::string& jar_prefix) {
   return StringPrintf("%s/framework/%s.jar", GetAndroidRoot(), jar_prefix.c_str());
 }
 
-std::string CommonRuntimeTest::GetLibCoreOatFileName() {
-  return GetOatFileName("core");
-}
-
-std::string CommonRuntimeTest::GetOatFileName(const std::string& oat_prefix) {
-  if (IsHost()) {
-    const char* host_dir = getenv("ANDROID_HOST_OUT");
-    CHECK(host_dir != nullptr);
-    return StringPrintf("%s/framework/%s.art", host_dir, oat_prefix.c_str());
-  }
-  return StringPrintf("%s/framework/%s.art", GetAndroidRoot(), oat_prefix.c_str());
-}
-
 std::string CommonRuntimeTest::GetTestAndroidRoot() {
   if (IsHost()) {
     const char* host_dir = getenv("ANDROID_HOST_OUT");
index 0fefc21..86b2de8 100644 (file)
@@ -97,12 +97,6 @@ class CommonRuntimeTest : public testing::Test {
   // Gets the path of the specified dex file for host or target.
   std::string GetDexFileName(const std::string& jar_prefix);
 
-  // Gets the path of the libcore oat file.
-  std::string GetLibCoreOatFileName();
-
-  // Gets the path of the specified oat file for host or target.
-  std::string GetOatFileName(const std::string& oat_prefix);
-
   std::string GetTestAndroidRoot();
 
   std::vector<const DexFile*> OpenTestDexFiles(const char* name)
index ae42284..9c6f8c4 100644 (file)
@@ -121,6 +121,13 @@ void Instrumentation::InstallStubsForMethod(mirror::ArtMethod* method) {
     // Do not change stubs for these methods.
     return;
   }
+  std::string temp;
+  // Note that the Proxy class itself is not a proxy class.
+  if (strcmp(method->GetDeclaringClass()->GetDescriptor(&temp), "Ljava/lang/reflect/Proxy;") == 0 &&
+      method->IsConstructor()) {
+    // Do not stub Proxy.<init>.
+    return;
+  }
   const void* new_portable_code;
   const void* new_quick_code;
   bool uninstall = !entry_exit_stubs_installed_ && !interpreter_stubs_installed_;
index 5af26b0..d977ce9 100644 (file)
 #include <jni.h>
 #include <vector>
 
-#include "common_runtime_test.h"
+#include "common_compiler_test.h"
 #include "field_helper.h"
 #include "mirror/art_field-inl.h"
 #include "scoped_thread_state_change.h"
 
 namespace art {
 
-class ProxyTest : public CommonRuntimeTest {
+class ProxyTest : public CommonCompilerTest {
  public:
   // Generate a proxy class with the given name and interfaces. This is a simplification from what
   // libcore does to fit to our test needs. We do not check for duplicated interfaces or methods and
@@ -103,12 +103,6 @@ class ProxyTest : public CommonRuntimeTest {
     soa.Self()->AssertNoPendingException();
     return proxyClass;
   }
-
- protected:
-  void SetUpRuntimeOptions(RuntimeOptions *options) OVERRIDE {
-    options->push_back(std::make_pair(StringPrintf("-Ximage:%s", GetLibCoreOatFileName().c_str()),
-                                      nullptr));
-  }
 };
 
 // Creates a proxy class and check ClassHelper works correctly.