1 # Copyright (C) 2017 The Android Open Source Project 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 .class public LSmali; 16 .super Ljava/lang/Object; 17 18 ## CHECK-START: double Smali.calcCircleAreaOrCircumference(double, boolean) load_store_elimination (before) 19 ## CHECK: NewInstance 20 ## CHECK: InstanceFieldSet 21 ## CHECK: ConstructorFence 22 ## CHECK: InstanceFieldGet 23 24 ## CHECK-START: double Smali.calcCircleAreaOrCircumference(double, boolean) load_store_elimination (after) 25 ## CHECK: NewInstance 26 ## CHECK-NOT: ConstructorFence 27 28 # The object allocation will not be eliminated by LSE because of aliased stores. 29 # However the object is still a singleton, so it never escapes the current thread. 30 # There should not be a constructor fence here after LSE. 31 32 .method public static calcCircleAreaOrCircumference(DZ)D 33 .registers 7 34 35 # CalcCircleAreaOrCircumference calc = 36 # new CalcCircleAreaOrCircumference( 37 # area_or_circumference ? CalcCircleAreaOrCircumference.TYPE_AREA : 38 # CalcCircleAreaOrCircumference.TYPE_CIRCUMFERENCE); 39 40 # if (area_or_circumference) { 41 # // Area 42 # calc.value = Math.PI * Math.PI * radius; 43 # } else { 44 # // Circumference 45 # calc.value = 2 * Math.PI * radius; 46 # } 47 48 # Please note that D8 would merge the iput togother which looks like : 49 50 # if (area_or_circumference) { 51 # // Area 52 # tmp = Math.PI * Math.PI * radius; 53 # } else { 54 # // Circumference 55 # tmp = 2 * Math.PI * radius; 56 # } 57 # calc.value = tmp; 58 59 # which makes the LSE valid and defeat the purpose of this test. 60 61 new-instance v0, LCalcCircleAreaOrCircumference; 62 63 if-eqz p2, :cond_15 64 65 const/4 v1, 0x0 66 67 :goto_5 68 invoke-direct {v0, v1}, LCalcCircleAreaOrCircumference;-><init>(I)V 69 70 if-eqz p2, :cond_17 71 72 const-wide v2, 0x4023bd3cc9be45deL # 9.869604401089358 73 74 mul-double/2addr v2, p0 75 76 iput-wide v2, v0, LCalcCircleAreaOrCircumference;->value:D 77 78 :goto_12 79 iget-wide v2, v0, LCalcCircleAreaOrCircumference;->value:D 80 81 return-wide v2 82 83 :cond_15 84 const/4 v1, 0x1 85 86 goto :goto_5 87 88 :cond_17 89 const-wide v2, 0x401921fb54442d18L # 6.283185307179586 90 91 mul-double/2addr v2, p0 92 93 iput-wide v2, v0, LCalcCircleAreaOrCircumference;->value:D 94 95 goto :goto_12 96 .end method 97 98