1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 package compiler.jvmci.compilerToVM; 26 27 import jdk.test.lib.Utils; 28 import sun.hotspot.WhiteBox; 29 30 import java.util.Random; 31 32 class DummyClass extends DummyAbstractClass { 33 private static final WhiteBox WB = WhiteBox.getWhiteBox(); 34 int p1 = 5; 35 int p2 = 6; 36 37 public int dummyInstanceFunction() { 38 String str1 = "123123123"; 39 double x = 3.14; 40 int y = Integer.parseInt(str1); 41 42 return y / (int) x; 43 } 44 45 public int dummyEmptyInstanceFunction() { 46 return 42; 47 } 48 49 public static int dummyEmptyStaticFunction() { 50 return -42; 51 } 52 53 @Override 54 public int dummyAbstractFunction() { 55 int z = p1 * p2; 56 return (int) (Math.cos(p2 - p1 + z) * 100); 57 } 58 59 @Override 60 public void dummyFunction() { 61 dummyEmptyInstanceFunction(); 62 } 63 64 public void withLoop() { 65 long tier4 = (Long) WB.getVMFlag("Tier4BackEdgeThreshold"); 66 for (long i = 0; i < tier4; ++i) { 67 randomProfile(); 68 } 69 } 70 71 private double randomProfile() { 72 String str1 = "123123123"; 73 double x = 3.14; 74 int y = Integer.parseInt(str1); 75 76 Random rnd = Utils.getRandomInstance(); 77 if (rnd.nextDouble() > 0.2) { 78 return y / (int) x; 79 } else { 80 return x / y; 81 } 82 } 83 84 }