Make sure classes with different access checks are not GVN-ed

Change-Id: I89f72fef3be35a4dd9585d97d03a3150386e0891
diff --git a/test/536-checker-needs-access-check/expected.txt b/test/536-checker-needs-access-check/expected.txt
index 7dc7a33..4acae95 100644
--- a/test/536-checker-needs-access-check/expected.txt
+++ b/test/536-checker-needs-access-check/expected.txt
@@ -1,3 +1,4 @@
 Got expected error instanceof
 Got expected error instanceof null
 Got expected error checkcast null
+Got expected error instanceof (keep LoadClass with access check)
diff --git a/test/536-checker-needs-access-check/src/Main.java b/test/536-checker-needs-access-check/src/Main.java
index 8b19daf..7bd49c1 100644
--- a/test/536-checker-needs-access-check/src/Main.java
+++ b/test/536-checker-needs-access-check/src/Main.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2015 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,10 +15,9 @@
  */
 
 import other.InaccessibleClass;
+import other.InaccessibleClassProxy;
 
 public class Main {
-    public static final boolean VERBOSE = false;
-
     public static void main(String[] args) {
         try {
             testInstanceOf();
@@ -37,6 +36,12 @@
         } catch (IllegalAccessError e) {
             System.out.println("Got expected error checkcast null");
         }
+
+        try {
+            testDontGvnLoadClassWithAccessChecks(new Object());
+        } catch (IllegalAccessError e) {
+            System.out.println("Got expected error instanceof (keep LoadClass with access check)");
+        }
     }
 
     /// CHECK-START: boolean Main.testInstanceOf() register (after)
@@ -59,5 +64,19 @@
         return (InaccessibleClass) null;
     }
 
+    /// CHECK-START: boolean Main.testDontGvnLoadClassWithAccessChecks(java.lang.Object) inliner (before)
+    /// CHECK: InvokeStaticOrDirect
+
+    /// CHECK-START: boolean Main.testDontGvnLoadClassWithAccessChecks(java.lang.Object) inliner (after)
+    /// CHECK-NOT: InvokeStaticOrDirect
+
+    /// CHECK-START: boolean Main.testDontGvnLoadClassWithAccessChecks(java.lang.Object) GVN (after)
+    /// CHECK: LoadClass needs_access_check:false
+    /// CHECK: LoadClass needs_access_check:true
+    public static boolean testDontGvnLoadClassWithAccessChecks(Object o) {
+        InaccessibleClassProxy.test(o);
+        return ic instanceof InaccessibleClass;
+    }
+
     public static InaccessibleClass ic;
 }
diff --git a/test/536-checker-needs-access-check/src/other/InaccessibleClass.java b/test/536-checker-needs-access-check/src/other/InaccessibleClass.java
index c49593d..de2e1d7 100644
--- a/test/536-checker-needs-access-check/src/other/InaccessibleClass.java
+++ b/test/536-checker-needs-access-check/src/other/InaccessibleClass.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2015 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/test/536-checker-needs-access-check/src/other/InaccessibleClassProxy.java b/test/536-checker-needs-access-check/src/other/InaccessibleClassProxy.java
new file mode 100644
index 0000000..4c005e4
--- /dev/null
+++ b/test/536-checker-needs-access-check/src/other/InaccessibleClassProxy.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package other;
+
+public class InaccessibleClassProxy {
+  public static boolean test(Object o) {
+    return o instanceof InaccessibleClass;
+  }
+}
diff --git a/test/536-checker-needs-access-check/src2/other/InaccessibleClass.java b/test/536-checker-needs-access-check/src2/other/InaccessibleClass.java
index ac804ac..2732263 100644
--- a/test/536-checker-needs-access-check/src2/other/InaccessibleClass.java
+++ b/test/536-checker-needs-access-check/src2/other/InaccessibleClass.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2015 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/test/536-checker-needs-access-check/src2/other/InaccessibleClassProxy.java b/test/536-checker-needs-access-check/src2/other/InaccessibleClassProxy.java
new file mode 100644
index 0000000..4c005e4
--- /dev/null
+++ b/test/536-checker-needs-access-check/src2/other/InaccessibleClassProxy.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package other;
+
+public class InaccessibleClassProxy {
+  public static boolean test(Object o) {
+    return o instanceof InaccessibleClass;
+  }
+}