diff options
| -rw-r--r-- | compiler/optimizing/prepare_for_register_allocation.cc | 2 | ||||
| -rw-r--r-- | test/529-checker-unresolved/expected.txt | 3 | ||||
| -rw-r--r-- | test/529-checker-unresolved/src/Main.java | 21 |
3 files changed, 25 insertions, 1 deletions
diff --git a/compiler/optimizing/prepare_for_register_allocation.cc b/compiler/optimizing/prepare_for_register_allocation.cc index d1770b75ab..63ef600756 100644 --- a/compiler/optimizing/prepare_for_register_allocation.cc +++ b/compiler/optimizing/prepare_for_register_allocation.cc @@ -96,7 +96,7 @@ void PrepareForRegisterAllocation::VisitClinitCheck(HClinitCheck* check) { if (can_merge_with_load_class && !load_class->HasUses()) { load_class->GetBlock()->RemoveInstruction(load_class); } - } else if (can_merge_with_load_class) { + } else if (can_merge_with_load_class && !load_class->NeedsAccessCheck()) { // Pass the initialization duty to the `HLoadClass` instruction, // and remove the instruction from the graph. load_class->SetMustGenerateClinitCheck(true); diff --git a/test/529-checker-unresolved/expected.txt b/test/529-checker-unresolved/expected.txt index 1e7dbfed2e..1590a2a280 100644 --- a/test/529-checker-unresolved/expected.txt +++ b/test/529-checker-unresolved/expected.txt @@ -5,3 +5,6 @@ UnresolvedClass.interfaceMethod() UnresolvedClass.superMethod() instanceof ok checkcast ok +UnresolvedClass.directCall() +UnresolvedClass.directCall() +UnresolvedClass.directCall() diff --git a/test/529-checker-unresolved/src/Main.java b/test/529-checker-unresolved/src/Main.java index 5219c04c37..9a04f1f9ca 100644 --- a/test/529-checker-unresolved/src/Main.java +++ b/test/529-checker-unresolved/src/Main.java @@ -138,6 +138,27 @@ public class Main extends UnresolvedSuperClass { callUnresolvedInstanceFieldAccess(c); testInstanceOf(m); testCheckCast(m); + testLicm(2); + } + + /// CHECK-START: void Main.testLicm(int) licm (before) + /// CHECK: <<Class:l\d+>> LoadClass loop:B2 + /// CHECK-NEXT: <<Clinit:l\d+>> ClinitCheck [<<Class>>] loop:B2 + /// CHECK-NEXT: <<New:l\d+>> NewInstance [<<Clinit>>,<<Method:i\d+>>] loop:B2 + /// CHECK-NEXT: InvokeUnresolved [<<New>>] loop:B2 + + /// CHECK-START: void Main.testLicm(int) licm (after) + /// CHECK: <<Class:l\d+>> LoadClass loop:none + /// CHECK-NEXT: <<Clinit:l\d+>> ClinitCheck [<<Class>>] loop:none + /// CHECK: <<New:l\d+>> NewInstance [<<Clinit>>,<<Method:i\d+>>] loop:B2 + /// CHECK-NEXT: InvokeUnresolved [<<New>>] loop:B2 + static public void testLicm(int count) { + // Test to make sure we keep the initialization check after loading an unresolved class. + UnresolvedClass c; + int i = 0; + do { + c = new UnresolvedClass(); + } while (i++ != count); } public static void expectEquals(byte expected, byte result) { |