1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // Note that $opt$ is a marker for the optimizing compiler to test 18 // it does compile the method. 19 20 public class Main { expectEquals(long expected, long result)21 public static void expectEquals(long expected, long result) { 22 if (expected != result) { 23 throw new Error("Expected: " + expected + ", found: " + result); 24 } 25 } 26 main(String[] args)27 public static void main(String[] args) { 28 long l = $opt$ReturnLong(); 29 expectEquals(42, l); 30 System.out.println("Long: " + l); 31 32 l = $opt$TakeOneLong1(42); 33 expectEquals(42, l); 34 35 l = $opt$TakeOneLong2(0, 42); 36 expectEquals(42, l); 37 38 l = $opt$TakeOneLong3(0, 1, 42); 39 expectEquals(42, l); 40 41 l = $opt$TakeOneLong4(0, 1, 2, 42); 42 expectEquals(42, l); 43 44 l = $opt$AddTwoLongs(42, 41); 45 expectEquals(83, l); 46 47 l = $opt$SubTwoLongs(42, 41); 48 expectEquals(1, l); 49 50 l = $opt$MakeCallsWithLongs1(); 51 expectEquals(57, l); 52 53 l = $opt$MakeCallsWithLongs2(); 54 expectEquals(900000000006L, l); 55 56 l = $opt$SubTwoLongs(-600000000006L, -200000000002L); 57 expectEquals(-400000000004L, l); 58 59 l = $opt$AddTwoLongs(-600000000006L, -200000000002L); 60 expectEquals(-800000000008L, l); 61 } 62 $opt$MakeCallsWithLongs1()63 static long $opt$MakeCallsWithLongs1() { 64 long l = $opt$SubTwoLongs(-600000000006L, -200000000002L); 65 expectEquals(-400000000004L, l); 66 67 l = $opt$AddTwoLongs(-600000000006L, -200000000002L); 68 expectEquals(-800000000008L, l); 69 70 return $opt$ReturnLong() + $opt$TakeOneLong1(1) + $opt$TakeOneLong2(0, 2) 71 + $opt$TakeOneLong3(0, 0, 3) + $opt$TakeOneLong4(0, 0, 0, 4) 72 // Test invoke-range. 73 + $opt$TakeOneLong5(0, 0, 0, 0, 5); 74 } 75 $opt$MakeCallsWithLongs2()76 static long $opt$MakeCallsWithLongs2() { 77 return $opt$AddThreeLongs(400000000003L, 200000000002L, 300000000001L); 78 } 79 $opt$ReturnLong()80 static long $opt$ReturnLong() { 81 return 42; 82 } 83 $opt$TakeOneLong1(long l)84 static long $opt$TakeOneLong1(long l) { 85 return l; 86 } 87 $opt$TakeOneLong2(int a, long l)88 static long $opt$TakeOneLong2(int a, long l) { 89 return l; 90 } 91 $opt$TakeOneLong3(int a, int b, long l)92 static long $opt$TakeOneLong3(int a, int b, long l) { 93 return l; 94 } 95 $opt$TakeOneLong4(int a, int b, int c, long l)96 static long $opt$TakeOneLong4(int a, int b, int c, long l) { 97 return l; 98 } 99 $opt$TakeOneLong5(int a, int b, int c,int d, long l)100 static long $opt$TakeOneLong5(int a, int b, int c,int d, long l) { 101 return l; 102 } 103 $opt$AddTwoLongs(long a, long b)104 static long $opt$AddTwoLongs(long a, long b) { 105 return a + b; 106 } 107 $opt$AddThreeLongs(long a, long b, long c)108 static long $opt$AddThreeLongs(long a, long b, long c) { 109 return a + b + c; 110 } 111 $opt$SubTwoLongs(long a, long b)112 static long $opt$SubTwoLongs(long a, long b) { 113 return a - b; 114 } 115 } 116